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 ¶
- func AllowRenderPanics(t testing.TB, next http.Handler) http.Handler
- func NewIsolatedDB(t *testing.T, adminDSN string, migrate func(*sql.DB) error) *sql.DB
- func NewIsolatedDBWithName(t *testing.T, adminDSN string, migrate func(*sql.DB) error) (*sql.DB, string)
- func RewriteDBNameForTest(dsn, dbName string) (string, error)
- func ValidateAdminDSN(dsn string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowRenderPanics ¶ added in v0.86.0
AllowRenderPanics returns a handler that keeps production HTTP status behavior after recovered render panics. Use it only to test intentional panic recovery. It does not silence error logs or TestHarness failure reporters.
The exemption ends at t.Cleanup; later requests through the returned handler again receive the test-only 500. Requests already admitted may finish with production status. Register server cleanup after calling this helper. It is safe with t.Parallel when each test owns its wrapper and server; never share the returned handler or server with tests that did not opt out. It panics outside a Go test binary. No request header or query opts out.
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package axetest is the axe-core accessibility-testing harness for GoFastr apps, host applications and the framework's own chromedp suites alike.
|
Package axetest is the axe-core accessibility-testing harness for GoFastr apps, host applications and the framework's own chromedp suites alike. |