pgtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package pgtest provides Postgres for integration tests: a Testcontainers server per test package (or FOREMAN_TEST_DATABASE_URL) and a freshly migrated schema per test.

var db *pgtest.Database
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m, &db)) }
pool := db.Pool(t); schema := db.Schema(t, pool)

Index

Constants

View Source
const DefaultImage = "postgres:17"

DefaultImage is the Postgres image used when FOREMAN_TEST_PG_IMAGE is unset.

Variables

This section is empty.

Functions

func LeakOptions

func LeakOptions() []goleak.Option

LeakOptions ignores the background goroutines of testcontainers and pgx pools.

func Main

func Main(m *testing.M, db **Database) int

Main is a TestMain body for integration test packages: it starts the database, runs the tests and checks for goroutine leaks.

Types

type Database

type Database struct {
	URL string
	// contains filtered or unexported fields
}

Database is a Postgres server shared by the tests of one package.

func Start

func Start(ctx context.Context) (*Database, error)

Start returns the server named by FOREMAN_TEST_DATABASE_URL, or starts a container from FOREMAN_TEST_PG_IMAGE (default postgres:17).

func (*Database) Close

func (d *Database) Close()

Close stops the container if this package started one.

func (*Database) Pool

func (d *Database) Pool(tb testing.TB) *pgxpool.Pool

Pool opens a pool on the database and closes it when the test ends.

func (*Database) Schema

func (d *Database) Schema(tb testing.TB, pool *pgxpool.Pool) string

Schema creates a fresh schema with the Foreman migrations applied and drops it when the test ends. Each test gets its own schema, so tests run in parallel against one server without interfering (channels are schema-prefixed too).

Jump to

Keyboard shortcuts

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