Utilities for testing Golang code that runs SQL.
This is a fork, to use:
go get github.com/hostwithquantum/sqltestutil
PostgresContainer is a Docker container running Postgres that can be used to cheaply start a throwaway Postgres instance for testing.
// Default 30 second timeout
pg, err := sqltestutil.StartPostgresContainer(ctx, "14")
// Custom timeout
pg, err := sqltestutil.StartPostgresContainer(ctx, "14", &sqltestutil.StartOption{
HealthCheckTimeout: 60 * time.Second,
})
// Custom image
pg, err := sqltestutil.StartPostgresContainer(ctx, "14", &sqltestutil.StartOption{
Image: "registry.example.org/repo/postgres",
})
// Debug for pull process (e.g. during CI)
pg, err := sqltestutil.StartPostgresContainer(ctx, "14", &sqltestutil.StartOption{
PullProgressWriter: os.Stdout,
})RunMigration reads all of the files matching *.up.sql in a directory and executes them in lexicographical order against the provided DB.
LoadScenario reads a YAML "scenario" file and uses it to populate the given DB.
Suite is a testify suite that provides a database connection for running tests against a SQL database.