Help us shape the future of Go! Take the 2026 Go Developer Survey

testing

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrAssertion = errors.New("testing: assertion failed")

SentinelError ensures errors are not silently dropped.

Functions

func AssertExists

func AssertExists(t testing.TB, conn *database.Connection, table string, where map[string]any)

AssertExists fails if the row matching where does not exist.

func AssertMissing

func AssertMissing(t testing.TB, conn *database.Connection, table string, where map[string]any)

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.

func Require

func Require(t testing.TB, err error)

Require fails t if err is non-nil.

func SQLite

func SQLite(t testing.TB, options ...Option) (*database.Connection, func())

SQLite opens a temporary SQLite database, runs all registered migrations, and returns a connection and a cleanup function. Use it inside TestMain or individual tests.

Types

type Option

type Option func(*opts)

Option configures the harness.

func WithLogger

func WithLogger(l *logger.Logger) Option

WithLogger enables SQL logging on the connection.

func WithMemory

func WithMemory(v bool) Option

WithMemory toggles the in-memory database (default true).

func WithMigrate

func WithMigrate(v bool) Option

WithMigrate toggles automatic migration on open.

func WithRegistry

func WithRegistry(r *migrations.Registry) Option

WithRegistry overrides the migrations registry.

Jump to

Keyboard shortcuts

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