Documentation
¶
Overview ¶
Package testdb provides helpers for creating isolated PostgreSQL databases in integration tests. Each test gets its own database with migrations applied, and the database is automatically dropped when the test completes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTestDB ¶
func CreateTestDB(ctx context.Context, t testing.TB, conf DBConfig, opts ...Option) (*sqlx.DB, error)
CreateTestDB provisions an isolated PostgreSQL database for a single test.
It creates a uniquely-named database, optionally applies migrations, and returns a connection to it. The database is automatically dropped when the test completes.
Types ¶
type DBConfig ¶
DBConfig holds the connection parameters for a PostgreSQL database.
type Option ¶
type Option func(*createConfig)
Option customises the behaviour of CreateTestDB.
func WithMigrationsPath ¶
WithMigrationsPath overrides the default migrations directory.
func WithSkipMigrations ¶
func WithSkipMigrations() Option
WithSkipMigrations skips running migrations — useful for testing missing-table error paths.