testfixture

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: MIT Imports: 11 Imported by: 0

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

func LoadSchema(t *testing.T, pool *pgxpool.Pool, fsys fs.FS, root string)

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

func PostgresContainer(t *testing.T, schema string) *pgxpool.Pool

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

func Truncate(t *testing.T, pool *pgxpool.Pool, schemas ...string)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL