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 ¶
const EnvDSN = "CORTEXDB_TEST_POSTGRES"
EnvDSN is the environment variable every PostgreSQL test opts in through.
Variables ¶
This section is empty.
Functions ¶
func DSN ¶
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 ¶
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.
Types ¶
This section is empty.