pgxtesting

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultURL

func GetDefaultURL() string

SetDefaultURL returns the default URL used to connect to the postgres server while creating and destorying test databases.

func GetEnvName

func GetEnvName() string

GetEnvName gets the enviroment variable name used to fetch the pgxpool URL, defaults name is PGURL.

func GetURL

func GetURL() string

GetURL returns the pgx pool URL from environment or the default value.

func SetDefaultURL

func SetDefaultURL(pgxurl string)

SetDefaultURL sets the default URL for postgres tests, panics if the url is invalid

func SetEnvName

func SetEnvName(name string)

SetEnvName sets the enviroment variable name used to fetch the pgxpool URL, defaults name is PGURL.

Types

type PoolURL

type PoolURL string

PoolURL makes for quick manipulation of some paramets that are important for tests. The url is expected to always be a valid URL, utility functions will panic if it's not.

func NewPoolURL

func NewPoolURL(poolURL string) (PoolURL, error)

NewPoolURL validates the input yurl

func (PoolURL) ConnURL

func (pu PoolURL) ConnURL() PoolURL

ConnURL returns a valid non pool connection url (can be used with go-migrate or sql.db)

func (PoolURL) Name

func (pu PoolURL) Name() string

Name returns the database name

func (PoolURL) SetName

func (pu PoolURL) SetName(dbName string) PoolURL

SetName sets the database name

func (PoolURL) String

func (pu PoolURL) String() string

type TestPool

type TestPool struct {
	*pgxpool.Pool
	Name string // database name
	URL  PoolURL
	// contains filtered or unexported fields
}

TestPool .

func CreateTestDatabase

func CreateTestDatabase(tb testing.TB, pgxPoolURL string) *TestPool

func CreateTestDatabaseEnv

func CreateTestDatabaseEnv(tb testing.TB) *TestPool

func (*TestPool) Close

func (t *TestPool) Close()

Close closes the test pool and deletes the testing database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL