testdb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var Image = "postgres:18-alpine"

Image is the Postgres image used when no server URL is configured.

Functions

func New

func New(t testing.TB) *pgxpool.Pool

New returns a pool connected to a fresh database cloned from the migrated template. The database is dropped when the test ends.

func NewFrom

func NewFrom(t testing.TB, template string) *pgxpool.Pool

NewFrom is New cloning template, a database made by Template ("" for the migrated template).

func Template

func Template(ctx context.Context, key string, fill func(*pgxpool.Pool) error) (string, error)

Template builds a database on top of the migrated template with fill (the demo data, say) and returns its name for NewFrom. Call it once per test binary: cloning is a few milliseconds where filling may take seconds.

func URL

func URL(pool *pgxpool.Pool) string

URL returns the connection URL of the database behind pool's config.

Types

This section is empty.

Jump to

Keyboard shortcuts

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