# README
sqltestutil
Utilities for testing Golang code that runs SQL.
Quick Start
# Postgres version is "12"
pg, _ := sqltestutil.StartPostgresContainer(context.Background(), "12")
defer pg.Shutdown(ctx)
db, err := sql.Open("postgres", pg.ConnectionString())
// ... execute SQL
Usage
PostgresContainer
PostgresContainer is a Docker container running Postgres that can be used to cheaply start a throwaway Postgres instance for testing.
RunMigration
RunMigration reads all of the files matching *.up.sql in a directory and executes them in lexicographical order against the provided DB.
LoadScenario
LoadScenario reads a YAML "scenario" file and uses it to populate the given DB.
Suite
Suite is a testify suite that provides a database connection for running tests against a SQL database.
# Functions
LoadScenario reads a YAML "scenario" file and uses it to populate the given db.
RunMigrations reads all of the files matching *.up.sql in migrationDir and executes them in lexicographical order against the provided db.
StartPostgresContainer starts a new Postgres Docker container.
WithDBName sets the DBName field of the PostgresContainerConfig.
WithDBPassword sets the DBPassword field of the PostgresContainerConfig.
WithDBUser sets the DBUser field of the PostgresContainerConfig.
WithSSLMode sets the SSLMode field of the PostgresContainerConfig.
WithTimeZone sets the TimeZone field of the PostgresContainerConfig.
# Structs
PostgresContainer is a Docker container running Postgres.
PostgresContainerConfig is a configuration struct for PostgresContainer.
Suite is a testify suite [1] that provides a database connection for running tests against a SQL database.
# Interfaces
ExecerContext is an interface used by MustExecContext and LoadFileContext.
# Type aliases
PostgresContainerConfig setter.