pgtest

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package pgtest runs Postgres-backed tests against one shared testcontainers Postgres per test binary.

Wire it up in TestMain and request a database per test:

func TestMain(m *testing.M) { os.Exit(pgtest.Run(m)) }

func TestSomething(t *testing.T) {
	pool := pgtest.New(t)
	...
}

The documented docs/postgres/schema.sql is loaded once into a template database; every New call clones it with CREATE DATABASE … TEMPLATE. Postgres tests run by default, are skipped with -short, and fail when Docker is unavailable.

Index

Constants

View Source
const DefaultImage = "postgres:18"

DefaultImage is the Postgres image used when ImageEnv is unset.

View Source
const ImageEnv = "GOUTILS_TEST_PG_IMAGE"

ImageEnv names the environment variable that overrides the Postgres image.

Variables

This section is empty.

Functions

func New

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

New returns a pool connected to a fresh database cloned from the schema template. The pool is closed and the database dropped when the test ends. It skips the test under -short.

func Run

func Run(m *testing.M) int

Run starts the shared Postgres container, loads schema.sql into the template database, runs the tests and tears everything down. It returns the exit code for os.Exit. With -short it runs the tests without Postgres.

Types

This section is empty.

Jump to

Keyboard shortcuts

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