Documentation
¶
Overview ¶
Package testutil boots a real, migrated Postgres for integration tests.
One shared pgvector-enabled container per test binary, migrated once, with tables truncated between tests rather than a database cloned per test.
Tests connect as a deliberately unprivileged role, not as the superuser the postgres image creates. That is load-bearing rather than tidiness: PostgreSQL exempts superusers from row-level security even when the table is FORCE'd, so a suite connecting as the default POSTGRES_USER would see every RLS policy silently do nothing and would pass whether or not tenant isolation actually works.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectScratchAs ¶ added in v0.3.0
ConnectScratchAs connects to the database pool is connected to, as another role. It exists for tests that need to observe the database as an unprivileged role rather than as the owner — which is the only way to see row-level security do anything at all.
func SetupScratchDatabase ¶
SetupScratchDatabase creates a fresh, empty database inside the shared container and returns an admin pool to it.
It exists so a test can run migrations — including rolling them back — without touching the migrated database every other test shares. Rolling back in the shared database would drop columns out from under whatever runs next.
func SetupTestPool ¶
SetupTestPool returns a pool connected to a shared, migrated Postgres as the unprivileged application role, starting the container on first use. It truncates the ragit tables via t.Cleanup so each test starts clean.
Skips under -short, so `go test -short ./...` needs no Docker.
Types ¶
This section is empty.