Documentation
¶
Overview ¶
Package pgtest is test support: it starts one Dockerized Postgres per test binary and hands out fresh databases — migrated pools via NewPool, or bare DSNs via FreshDB for suites that exercise store.Open/Migrate themselves. Every Postgres-backed suite uses it; production code must never import it. A missing Docker daemon is a hard failure, not a skip: skipped contract tests would silently hollow out the coverage gate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FreshDB ¶ added in v0.2.0
FreshDB creates a new empty database in the shared container and returns its DSN, un-migrated, so a suite can exercise store.Open/Migrate itself from a clean slate.
func Main ¶
Main wraps testing.M: it starts the shared container, runs the suite, and tears the container down. Use from TestMain: os.Exit(pgtest.Main(m)). The start is attempted twice, with a fresh container in between (#265; see readyTimeout). The retry is unconditional on the error's class because even a failed `docker run` can be load-induced (port programming races under a crowded daemon); when the daemon is simply absent, the second attempt fails in milliseconds and costs nothing.
func NewPool ¶
NewPool creates a fresh database in the shared container, migrates it, and returns a pool closed at test end.
func NewSession ¶
NewSession inserts the minimum fixture rows (agent, agent version, environment of the given kind, session) and returns the session and environment ids.
func NewSessionInEnv ¶
NewSessionInEnv inserts an additional idle session (with its own throwaway agent + version) into an existing environment and returns the session id. Use it to place several sessions — and thus several work items — under one environment, since Enqueue dedupes per (session, kind) while a live item exists.
Types ¶
This section is empty.