Documentation
¶
Overview ¶
Package testing provides helpers for running migrations against an ephemeral SQLite database, useful for unit and integration tests.
Importing this package introduces a transitive dependency on the SQLite driver and the migrations engine; tests in production code may want a thinner harness.
Index ¶
- Variables
- func AssertExists(t testing.TB, conn *database.Connection, table string, where map[string]any)
- func AssertMissing(t testing.TB, conn *database.Connection, table string, where map[string]any)
- func MustMigrate(t testing.TB, conn *database.Connection)
- func Require(t testing.TB, err error)
- func SQLite(t testing.TB, options ...Option) (*database.Connection, func())
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrAssertion = errors.New("testing: assertion failed")
SentinelError ensures errors are not silently dropped.
Functions ¶
func AssertExists ¶
AssertExists fails if the row matching where does not exist.
func AssertMissing ¶
AssertMissing fails if a row matching where exists.
func MustMigrate ¶
func MustMigrate(t testing.TB, conn *database.Connection)
MustMigrate runs the migrator and fails t on error.
Types ¶
type Option ¶
type Option func(*opts)
Option configures the harness.
func WithLogger ¶
WithLogger enables SQL logging on the connection.
func WithMemory ¶
WithMemory toggles the in-memory database (default true).
func WithRegistry ¶
func WithRegistry(r *migrations.Registry) Option
WithRegistry overrides the migrations registry.