Documentation
¶
Overview ¶
Package testfixture provides Postgres test infrastructure for paper-board services: a process-shared testcontainers Postgres, schema-bootstrap, and per-test truncation.
Lifecycle: PostgresContainer spins one container per test process via sync.Once. The container terminates on process exit; testcontainers' Reaper reaps any leftovers. Per-test isolation is the caller's responsibility — invoke Truncate(t, pool, schema) after each test.
Build tag — package compiles unconditionally; tests using it must be tagged `//go:build integration` and run as `go test -tags=integration ./...`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectionString ¶
func ConnectionString() string
ConnectionString returns the URL of the shared container. Returns "" when PostgresContainer has not been called yet.
func LoadSchema ¶
LoadSchema applies every `*.up.sql` file under fsys/root to pool, in lexical order. Use to bootstrap a service schema once per test package, typically from the service's embedded migrations:
import "github.com/paper-board/agents/migrations" testfixture.LoadSchema(t, pool, migrations.SchemaFS, "schema")
LoadSchema does NOT run inside a transaction — migrations may include CREATE EXTENSION or other tx-incompatible statements; each file's BEGIN/COMMIT is honoured by Postgres at exec time.
func PostgresContainer ¶
PostgresContainer returns a *pgxpool.Pool connected to a process-shared Postgres container. The container installs cluster-wide extensions (pgcrypto + citext) on first call, and creates the requested schema. Subsequent calls within the same test process reuse the pool.
func Truncate ¶
Truncate issues TRUNCATE ... RESTART IDENTITY CASCADE on every base table within the given schemas. Cheaper than DROP+recreate, preserves indexes, resets sequence counters. Skips schemas with no tables.
Call after each test (or in t.Cleanup) to give every test a clean slate against the shared container.
Types ¶
This section is empty.