Documentation
¶
Overview ¶
Package dbtest provides an isolated PostgreSQL handle for store tests.
Strategy (fast on slow disks): migrate ONE schema per test process, then make each test independent by TRUNCATEing its tables (milliseconds) instead of creating/migrating a fresh schema or database per test (hundreds of ms × thousands of tests → package timeouts). No test uses t.Parallel(), so within a process tests run sequentially and the truncate-between-tests is safe; across processes each gets its own schema (keyed by pid).
- JACKUI_TEST_DATABASE_URL set → use that Postgres (the CI path).
- otherwise → t.Skip.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDB ¶
NewDB returns a *sql.DB scoped to this process's migrated schema. On the first call within a test it TRUNCATEs all tables (re-seeding the anonymous user), so each test starts clean. Returns a fresh handle each call (safe to Close in the "closed pool" error-path tests without affecting other handles). Skips when no test database is configured.
func NewIsolatedDB ¶
NewIsolatedDB returns a pool scoped to a PRIVATE, freshly-migrated schema, dropped on cleanup. Slower than NewDB (full migration per call) — use it only for the rare tests that mutate the schema itself (e.g. DROP TABLE to force a store error), which can't share NewDB's process-wide schema.
Types ¶
This section is empty.