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

pgtest

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pgtest confines each test that writes to a live PostgreSQL to a schema of its own.

`go test ./...` runs packages in parallel, and more than one of them opens the database CHRONICLE_TEST_POSTGRES_DSN names. Store.Migrate runs every migration's ALTER TABLE on each call, so two packages migrating and appending in the shared public schema at once can deadlock each other. A schema per test gives each one tables nobody else touches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Schema

func Schema(t testing.TB, dsn string) string

Schema creates a randomly named schema in the database dsn names, drops it again when the test ends, and returns dsn with search_path pinned to it. The migrations create their tables unqualified, so they land inside it.

Open the pool on the returned DSN after calling Schema. Cleanups run last registered first, so the pool's close then fires before the drop, which would otherwise block on the pool's open connections.

It refuses the default port. On the machine these tests were written on, that is another project's live database.

Types

This section is empty.

Jump to

Keyboard shortcuts

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