Documentation
¶
Overview ¶
Package testkit provides PUBLIC test helpers for host apps that use the GoFastr framework. The framework-internal counterparts live in framework/internal/testdb and are intentionally unexported so outside callers can't accidentally couple to their schema-based isolation strategy.
The most common helper is NewIsolatedDB — it carves a fresh, named Postgres database for the duration of a single test and drops it on t.Cleanup. Use it from host apps' integration tests that want true per-test isolation against a real cluster.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewIsolatedDB ¶
NewIsolatedDB carves a fresh Postgres database on the cluster that adminDSN points at, runs the supplied migrate callback against it, and returns a connection to the carved DB. The DB is dropped (and any lingering backends terminated) on t.Cleanup.
adminDSN must be a connection string with permission to create and drop databases (typically a superuser connecting to a maintenance DB like `postgres`). The helper hard-fails on missing or unusable DSNs — by design, never t.Skip. Tests that hand-roll t.Skip when a DB is missing pass without proving anything; this helper inverts that.
migrate is called exactly once with the connection to the new DB before the helper returns. Pass nil to skip schema setup.
func NewIsolatedDBWithName ¶
func NewIsolatedDBWithName(t *testing.T, adminDSN string, migrate func(*sql.DB) error) (*sql.DB, string)
NewIsolatedDBWithName is NewIsolatedDB but also returns the carved database name. Useful in tests that want to verify the DB exists independently of the returned connection.
func RewriteDBNameForTest ¶
RewriteDBNameForTest exposes rewriteDBName to the external test package so the parse-failure contract can be asserted directly. Not intended for production callers.
func ValidateAdminDSN ¶
ValidateAdminDSN returns an error if the DSN is empty or obviously malformed. Exposed so tests can check the failure mode directly.
Types ¶
This section is empty.