Documentation
¶
Index ¶
- func GetTestDataDir() (string, error)
- type TestDatabaseContainer
- func (td *TestDatabaseContainer) CreateSnapshot(name string) error
- func (td *TestDatabaseContainer) ExecuteDir(dirpath string) error
- func (td *TestDatabaseContainer) ExecuteFile(path string) (int64, error)
- func (td *TestDatabaseContainer) NewPgxConnection() (*pgx.Conn, error)
- func (td *TestDatabaseContainer) NewPgxPoolConnection() (*pgxpool.Pool, error)
- func (td *TestDatabaseContainer) NewSqlDbConnection() (*sql.DB, error)
- func (td *TestDatabaseContainer) RestoreSnapshot(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTestDataDir ¶
GetTestDataDir is a helper function that will return the testdata directory for package in which it is invoked. If the testdata directory has been created in another package or the files exist outside the package, they will not be found.
Types ¶
type TestDatabaseContainer ¶
type TestDatabaseContainer struct { Container *postgres.PostgresContainer ConnectionString string // contains filtered or unexported fields }
func NewTestDatabaseContainer ¶
func NewTestDatabaseContainer() (TestDatabaseContainer, error)
Returns a new postgres container with migrations from db/migrations/bcda applied and seed data from db/testdata applied.
func (*TestDatabaseContainer) CreateSnapshot ¶
func (td *TestDatabaseContainer) CreateSnapshot(name string) error
CreateSnapshot will create a snapshot for a given name. Close any active connections to the database before taking a snapshot.
func (*TestDatabaseContainer) ExecuteDir ¶
func (td *TestDatabaseContainer) ExecuteDir(dirpath string) error
ExecuteFile will execute all *.sql files for the provided dirpath. Is it recommended to use the package's testdata/ directory to add test files. A package's testdata/ dir can be retrieved with GetTestDataDir().
func (*TestDatabaseContainer) ExecuteFile ¶
func (td *TestDatabaseContainer) ExecuteFile(path string) (int64, error)
ExecuteFile will execute a *.sql file for a database container. Sql files for testing purposes should be under a package's testdata/ directory.
func (*TestDatabaseContainer) NewPgxConnection ¶
func (td *TestDatabaseContainer) NewPgxConnection() (*pgx.Conn, error)
Return a pgx connection for a given database container.
func (*TestDatabaseContainer) NewPgxPoolConnection ¶
func (td *TestDatabaseContainer) NewPgxPoolConnection() (*pgxpool.Pool, error)
Return a pgx pool for a given database container.
func (*TestDatabaseContainer) NewSqlDbConnection ¶
func (td *TestDatabaseContainer) NewSqlDbConnection() (*sql.DB, error)
Return a sql/db connection for a given database container.
func (*TestDatabaseContainer) RestoreSnapshot ¶
func (td *TestDatabaseContainer) RestoreSnapshot(name string) error
RestoreSnapshot will restore the snapshot that is taken after the database container has had the initial migrations and data seed applied. If no name is provided, it will restore the default snapshot. "Base" will restore the database to it's init state.