Documentation
¶
Overview ¶
Package pgtest provides a Postgres testing harness used by every Postgres-backed synapse store. It manages a single per-binary testcontainers Postgres instance and hands out fresh per-test databases backed by a pgxpool.
Usage from a backend's *_test.go:
func newStore(tb testing.TB) *mystore.Store {
tb.Helper()
pool := pgtest.Pool(tb)
store, err := mystore.New(tb.Context(), pool)
if err != nil { tb.Fatalf("New: %v", err) }
return store
}
One container per test binary (initialized lazily on first Pool call), one database per test. Per-test databases are cleaned up after the test completes; the container is left running for the remainder of the binary's lifetime and is reaped when the process exits.
LISTEN/NOTIFY channels in Postgres are scoped per database, so the per-test database isolation extends to pub/sub state — exactly what the Postgres event store's subscription tests need.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Pool ¶
Pool returns a *pgxpool.Pool connected to a fresh per-test database. Lazily starts a Postgres container the first time it is called in the test binary; subsequent calls reuse the container.
The pool, the per-test database, and (eventually, on process exit) the container are cleaned up automatically. If Docker is unavailable or the container fails to start, Pool calls tb.Skip with a descriptive reason so tests degrade gracefully on machines without Docker.
Types ¶
This section is empty.