dbtest

package
v0.68.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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