pgtest

package
v2.111.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pgtest gives a test its own PostgreSQL schema.

`go test ./...` runs package binaries in parallel, and every PostgreSQL test in this module reads one DSN from CORTEXDB_TEST_POSTGRES. Sharing a schema across them is the arrangement that produces failures nobody can reproduce: one package's DROP TABLE ... CASCADE lands while another is mid-test, and the second fails naming a table it never wrote. Re-running that package alone passes, which is the worst way for a defect to present — it reads as flakiness in the test rather than as a shared resource nobody claimed.

Two packages already worked around it by hand. This is that workaround, in one place, so a new PostgreSQL test gets the isolation by default rather than by remembering.

Index

Constants

View Source
const EnvDSN = "CORTEXDB_TEST_POSTGRES"

EnvDSN is the environment variable every PostgreSQL test opts in through.

Variables

This section is empty.

Functions

func DSN

func DSN(t *testing.T, prefix string) string

DSN returns a DSN scoped to a schema created for this test, and "" when EnvDSN is unset — a caller that gets "" should skip, and say in the skip message what is therefore not covered.

The schema is named for the caller and dropped when the test ends. public stays on the search_path so the vector type still resolves: the extension is installed once, in the shared schema, under a lock.

func Database

func Database(t *testing.T, prefix string) string

Database gives the calling test a PostgreSQL database of its own, and returns its DSN — "" when EnvDSN is unset.

A schema is enough to isolate tables; it is not enough for anything database-wide. CREATE and DROP EXTENSION are database-wide: a test that removes an extension to see what happens without it would strip the type off every other package's tables mid-run. No extension is installed here, because what such a test is usually studying is the installing.

func Open

func Open(t *testing.T, prefix string) *sql.DB

Open is DSN with the connection already made. It returns nil when EnvDSN is unset, so a caller can branch on that alone.

Types

This section is empty.

Jump to

Keyboard shortcuts

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