testhelpers

package module
v0.0.0-...-a354bcb Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 15 Imported by: 0

README

testhelpers

Helpful tools for running go tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTestDb

func CleanupTestDb(db *sqlx.DB) error

CleanupTestDb truncates tables that are usually populated with fixtures. The set of tables is hardcoded.

func DropAllTables

func DropAllTables(db *sqlx.DB) error

DropAllTables enumerates all tables and drops them.

func InitializeDatabase

func InitializeDatabase(db *sqlx.DB, migrationsDir, fixturesDir string) error

InitializeDatabase drops all tables in the provided database, then runs the migrations found in the migrationsDir, then loads the fixtures found in fixturesDir.

func LoadFixtures

func LoadFixtures(db *sqlx.DB, fixturesDirectory string) error

LoadFixtures scans the given directory for .sql files and runs all of them on the given DB handle. They will run in filesystem order, not sorted.

Types

type PostgresConfig

type PostgresConfig struct {
	// Used to configure the database
	Username string
	Password string
	Database string

	// Used to generate the database name
	Service string
	Realm   string
	// contains filtered or unexported fields
}

func (*PostgresConfig) Cleanup

func (cfg *PostgresConfig) Cleanup(ctx context.Context) error

func (*PostgresConfig) GetContainerName

func (cfg *PostgresConfig) GetContainerName() string

func (*PostgresConfig) GetDbConn

func (cfg *PostgresConfig) GetDbConn() (*sqlx.DB, error)

func (*PostgresConfig) GetDbVar

func (cfg *PostgresConfig) GetDbVar() string

func (*PostgresConfig) GetPasswordVar

func (cfg *PostgresConfig) GetPasswordVar() string

func (*PostgresConfig) GetPort

func (cfg *PostgresConfig) GetPort() int

func (*PostgresConfig) GetUserVar

func (cfg *PostgresConfig) GetUserVar() string

func (*PostgresConfig) LaunchDockerInstance

func (cfg *PostgresConfig) LaunchDockerInstance(ctx context.Context) (*sqlx.DB, error)

Jump to

Keyboard shortcuts

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