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 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pgtest gives each test its own throwaway Postgres database, so no test depends on the compose stack's database or on another test.

The package exports:

  • Scratch, which creates an empty database on any administrative connection and returns its name
  • Open, which creates one on the server MESSAGING_DSN names and returns a session over it
  • DSN, which points an administrative connection string at a scratch database, and Pool, which opens a pool on one

Scratch serves a service's domain tests and the harness that points a service process at its database; Open serves the engine's own integration suite. Each database is dropped when the test ends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(t testing.TB, admin, name string) string

DSN is admin with its database replaced by name.

func Open

func Open(t testing.TB) *sqlate.DB

Open creates a uniquely named database and returns a session over a pool connected to it. A missing MESSAGING_DSN fails the test: the integration tag states that the stack is expected.

func Pool

func Pool(t testing.TB, dsn string) *sql.DB

Pool opens a pool on dsn and pings it, closing it when the test ends.

func Scratch

func Scratch(t testing.TB, admin, prefix string) string

Scratch creates a uniquely named, empty database, <prefix>_test_<hex>, on the server admin connects to, and returns its name. It drops the database when the test ends, ending any session still open on it, such as a service process's pool.

Types

This section is empty.

Jump to

Keyboard shortcuts

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