Documentation
¶
Overview ¶
Package testdb provides shared per-test database helpers used by the framework's internal tests AND by framework_test (external) tests that can't access package-private helpers.
Live in framework/internal/ so battery tests and downstream consumers can't depend on it — these helpers are tied to gofastr's test fixtures and shouldn't leak into product code.
Index ¶
- Variables
- func ForEachDialect(t *testing.T, fn func(t *testing.T, db *sql.DB, dialect migrate.Dialect))
- func NewSchemaName(t *testing.T) string
- func Open(t *testing.T, dialect migrate.Dialect) *sql.DB
- func RedactDSN(dsn string) string
- func ResolvePostgresOnce() (string, error)
- func WaitPGReady(db *sql.DB) error
Constants ¶
This section is empty.
Variables ¶
var Dialects = []migrate.Dialect{migrate.DialectSQLite, migrate.DialectPostgres}
Dialects is the canonical list of dialects ForEachDialect iterates.
Functions ¶
func ForEachDialect ¶
ForEachDialect runs fn against every dialect in Dialects as a t.Run subtest. Postgres subtests are skipped (not failed) when no PG is reachable.
func NewSchemaName ¶
NewSchemaName produces a unique, lowercase, identifier-safe schema name from the test's name plus a process-local counter. Postgres identifiers have a 63-byte cap; truncated aggressively.
func Open ¶
Open returns a fresh database for the given dialect. SQLite is an in-memory database with foreign keys enabled. Postgres connects to the shared resolved instance, creates a unique per-test schema, and sets the connection's search_path to that schema. Cleanup is registered via t.Cleanup.
func ResolvePostgresOnce ¶
ResolvePostgresOnce returns a base DSN to a working Postgres or an error describing why one isn't reachable. Resolution is memoised across all tests in the process.
func WaitPGReady ¶
WaitPGReady pings the database with linear backoff until it answers or the total deadline expires. Bounded to ~5s.
Types ¶
This section is empty.