Documentation
¶
Overview ¶
Package pgtest provides a shared real-Postgres test harness usable from any package in the module (core/migrate, cmd/gofastr, …) without importing framework/internal/testdb, which is import-restricted to the framework tree.
Resolution order (memoised once per process):
- TEST_POSTGRES_DSN env var — point CI at an existing server.
- testcontainers postgres:16-alpine — spun up on demand (needs Docker).
- neither reachable → tests call t.Skip via DB/DSN.
Each DB(t) hands back a connection scoped to a unique schema (search_path), so concurrent tests don't collide, with cleanup registered on t.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseDSN ¶
BaseDSN returns the resolved base DSN (the maintenance/default database), or skips the test if Postgres is unreachable. Use for EnsureDatabase / CLI round-trips that need a raw connection string.
func DB ¶
DB returns a *sql.DB scoped to a fresh, uniquely-named schema (via search_path) on the shared Postgres, or skips if Postgres is unreachable. The schema and connection are dropped/closed on t.Cleanup.
func FreshDatabaseDSN ¶
FreshDatabaseDSN creates a uniquely-named database on the shared Postgres and returns a URL DSN pointing at it, dropped on t.Cleanup. Use for CLI / tooling tests that connect by URL string and expect to own the database (vs DB(t), which schema-scopes a shared one). Skips if Postgres is unreachable, or if the base DSN isn't URL-form.
func UnusedDSN ¶
UnusedDSN returns a URL DSN pointing at a uniquely-named database that does NOT yet exist, plus a cleanup that drops it if something created it. Use to test database-creation paths (EnsureDatabase / migrate up --create-db). Skips if Postgres is unreachable or the base DSN isn't URL-form.
Types ¶
This section is empty.