royge / poptest

A utility package that can be used when testing with gobuffalo pop connection.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

poptest

Go Go Report Card

A utility package that can be used when testing with gobuffalo pop connection.

The primary goal of this package is to override the database name from the database.yml programatically.

How To Use

go get github.com/royge/poptest

Example:

import (
	"fmt"
	"strings"

	"github.com/royge/poptest"

	pop "github.com/gobuffalo/pop/v6"
)

// ExampleDeets show the primary purpose of this package.
// You can see that I override the test-mydb database name from database.yml
// with random-db-name.
func ExampleDeets() {
	deets, err := poptest.Deets("test", func(d *pop.ConnectionDetails) error {
		fmt.Println("original:", d.URL)

		name := "random-db-name"
		d.URL = strings.Replace(d.URL, "test-mydb", name, 1)

		return nil
	})
	if err != nil {
		panic("don't panic")
	}

	fmt.Println("new:", deets.URL)

	// Output:
	// original: postgres://postgres:password@127.0.0.1:5432/test-mydb?sslmode=disable
	// new: postgres://postgres:password@127.0.0.1:5432/random-db-name?sslmode=disable
}

About

A utility package that can be used when testing with gobuffalo pop connection.

License:MIT License


Languages

Language:Go 100.0%