Help us shape the future of Go! Take the 2026 Go Developer Survey

pgtest

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package pgtest gives each test a fresh PostgreSQL database cut from a migrated template, and sweeps stale ones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrator

func Migrator(hash string, migrate func(ctx context.Context, db *sql.DB) error) pgtestdb.Migrator

Migrator returns a pgtestdb migrator that builds its template with migrate once per hash.

func New

func New(t testing.TB, address string, migrator pgtestdb.Migrator) string

New returns the escaped address of a fresh database cut from the template migrator builds on the server of address.

func NewSwept added in v0.2.0

func NewSwept(t testing.TB, address string, olderThan time.Duration, migrator pgtestdb.Migrator) string

NewSwept sweeps the stale test databases of the server at address once per test process, then answers New.

func Sweep

func Sweep(ctx context.Context, address string, olderThan time.Duration) ([]string, error)

Sweep drops each pgtestdb instance older than olderThan with no session on it, and returns the names it dropped.

func URL

func URL(cfg pgtestdb.Config) string

URL returns the address of the database cfg describes, with its user, password and database name escaped.

Types

This section is empty.

Jump to

Keyboard shortcuts

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