testdb

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

Dialects is the canonical list of dialects ForEachDialect iterates.

Functions

func ForEachDialect

func ForEachDialect(t *testing.T, fn func(t *testing.T, db *sql.DB, dialect migrate.Dialect))

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

func NewSchemaName(t *testing.T) string

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

func Open(t *testing.T, dialect migrate.Dialect) *sql.DB

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 RedactDSN

func RedactDSN(dsn string) string

RedactDSN strips the password from a Postgres URL for log output.

func ResolvePostgresOnce

func ResolvePostgresOnce() (string, error)

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

func WaitPGReady(db *sql.DB) error

WaitPGReady pings the database with linear backoff until it answers or the total deadline expires. Bounded to ~5s.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL