Documentation
¶
Overview ¶
Package dentest provides test helpers for opening a Den database in a temporary directory (SQLite) or against a reachable PostgreSQL instance. It is intended for use from `_test.go` files only.
Import guidance ¶
Do NOT import this package from production code. It side-effect-imports BOTH backend packages (SQLite and PostgreSQL) so that callers get either scheme registered without extra setup. A production binary that drags in dentest therefore links in the drivers for the backend it doesn't use — modernc.org/sqlite and jackc/pgx/v5 each contribute several MB to the final binary and are completely unnecessary when only one backend is in play. The helpers also accept a *testing.TB, which ties them to the testing package in ways that make them unsuitable for production contexts in the first place.
No build constraint enforces the test-only restriction — the package stays importable from production code so it remains ergonomic for the common case (tests across a module). Keep dentest imports confined to files whose names end in `_test.go` and any reasonable code review will catch accidental leaks.
Index ¶
- func MustOpen(t testing.TB, types ...any) *den.DB
- func MustOpenPostgres(t testing.TB, connString string, types ...any) *den.DB
- func MustOpenPostgresDefault(t testing.TB, types ...any) *den.DB
- func MustOpenPostgresWith(t testing.TB, connString string, types []any, opts []den.Option) *den.DB
- func MustOpenWith(t testing.TB, types []any, opts []den.Option) *den.DB
- func PostgresURL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustOpen ¶
MustOpen creates a file-backed SQLite Den database in a temp directory for testing. It registers the given document types and automatically closes the database when the test ends.
func MustOpenPostgres ¶
MustOpenPostgres creates a PostgreSQL-backed Den database for testing.
func MustOpenPostgresDefault ¶ added in v0.11.0
MustOpenPostgresDefault is MustOpenPostgres with the connection string defaulted to PostgresURL — i.e. the DEN_POSTGRES_URL env var or the local fallback. Prefer this helper when the test does not need to override the connection string; it mirrors MustOpen's no-URL ergonomics for the PostgreSQL path.
func MustOpenPostgresWith ¶
MustOpenPostgresWith creates a PostgreSQL-backed Den database with options. Registered collections are automatically dropped when the test ends.
func MustOpenWith ¶
MustOpenWith creates a file-backed SQLite Den database with options.
func PostgresURL ¶
func PostgresURL() string
PostgresURL returns the PostgreSQL connection string from the DEN_POSTGRES_URL environment variable, falling back to a local default.
Types ¶
This section is empty.