Documentation
¶
Overview ¶
Package dbtest provisions a database for integration tests.
It is imported only from _test.go files, so testcontainers-go (and the Docker client it drags in) never ends up in the production airlock binary. It deliberately does NOT import airlock/db: the migrate behaviour is injected by the caller, which keeps this package free of any import cycle with the package under test.
Setup starts a throwaway pgvector/pgvector:pg17 container (the exact prod image), migrates it, and snapshots the migrated state as a template. The returned reset restores that template (DROP + CREATE DATABASE ... WITH TEMPLATE) so every test starts from the exact post-migration state — including migration-seeded singleton rows like system_settings — without re-running migrations. When Docker is unreachable, ok is false and DB tests skip.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Setup ¶
func Setup( ctx context.Context, migrate func(dsn string) error, ) (dsn string, reset func() error, release func(), ok bool)
Setup provisions a migrated database for the calling test package.
- dsn: the connection string tests should use.
- reset: restores the post-migration snapshot. Because reset drops and recreates the database, the caller MUST close and rebuild its connection pool around each reset call.
- release: torn down from TestMain after m.Run().
- ok: false when no database could be provisioned (no Docker); callers should still run non-DB tests and let DB tests skip.
Pass db.RunMigrations as migrate.
Types ¶
This section is empty.