dbtest

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dbtest gives tests an isolated, fully-migrated PostgreSQL database with no external server to run. It starts one embedded server per test binary, migrates a template once, and hands each test a fresh database cloned from that template — real commits and all, so concurrency behaviour (advisory locks, transactions) is exercised exactly as in production.

Use it from a test package like:

func TestMain(m *testing.M) { dbtest.Main(m) }

func TestThing(t *testing.T) {
	db := dbtest.New(t)
	// ... db is a clean, migrated *pgxpool.Pool; dropped when the test ends
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M)

Main runs a package's tests against the shared embedded server and stops it afterward. Test packages that use New call this from TestMain so the server process and its data directory are cleaned up when the binary exits.

func New

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

New returns a fresh, isolated, fully-migrated database for the calling test and registers its teardown. Each call clones the shared template, so tests neither see each other's data nor re-run migrations.

Types

This section is empty.

Jump to

Keyboard shortcuts

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