Documentation
¶
Overview ¶
Package testdb gives integration tests a fresh, migrated Postgres database.
The first call starts Postgres 18 with testcontainers (or uses the server in REPUTECAST_TEST_DATABASE_URL, which is faster locally: point it at the docker compose Postgres), migrates a template database once, and then clones it per test with CREATE DATABASE … TEMPLATE, which takes a few ms. Each run first drops what finished runs left behind (see sweep).
Index ¶
- Variables
- func Empty(t testing.TB) string
- func New(t testing.TB) *pgxpool.Pool
- func NewFrom(t testing.TB, template string) *pgxpool.Pool
- func Shared(ctx context.Context, key string, ...) (name, dir string, err error)
- func Template(ctx context.Context, key string, fill func(*pgxpool.Pool) error) (string, error)
- func URL(pool *pgxpool.Pool) string
Constants ¶
This section is empty.
Variables ¶
var Image = "postgres:18-alpine"
Image is the Postgres image used when no server URL is configured.
Functions ¶
func Empty ¶
Empty creates an empty database (no migrations) and returns its URL; it is dropped when the test ends. For tests of migrating itself.
func New ¶
New returns a pool connected to a fresh database cloned from the migrated template. The database is dropped when the test ends.
func NewFrom ¶
NewFrom is New cloning template, a database made by Template ("" for the migrated template).
func Shared ¶
func Shared(ctx context.Context, key string, fill func(pool *pgxpool.Pool, dir string) error) (name, dir string, err error)
Shared is Template filled once per `go test` run rather than once per test binary: the first binary to ask fills it, the others wait for it and reuse it. fill writes the database through pool and any files into dir, which the caller copies for each clone. key names the fill and must change with anything that changes what fill writes.
Types ¶
This section is empty.