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 may open the database WEAVE_TEST_POSTGRES_DSN names. A schema per test gives each one tables nobody else touches.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Database ¶
Database creates a randomly named database on the server dsn names, drops it when the test ends, and returns dsn pointed at it. A fresh database has no extensions, so a test can see pgvector as available but not installed.
func Schema ¶
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. Weave's migrations create their tables unqualified, so they land inside it.
Open the store on the returned DSN after calling Schema. Cleanups run last registered first, so the store's close fires before the drop.
It refuses the default port: on the machines these tests run on, that is somebody's live database.
func SchemaWithVector ¶
SchemaWithVector is Schema for a test that needs the pgvector extension. It creates the extension in public once per database and pins search_path to the new schema, then public, so the vector type resolves while the test's tables still land in its own schema.
The extension lives in public rather than the test schema because dropping a schema that holds it would drop it for every other test on the database. Two packages creating it at once can collide on pg_extension's unique index (SQLSTATE 23505); the loser finds it there and carries on.
Types ¶
This section is empty.