dbtest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dbtest has test helpers for code that uses migro: database assertions, a database that rolls back when the test ends, and a query counter (Laravel's assertDatabaseHas, RefreshDatabase and assertQueryCount).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDatabaseCount

func AssertDatabaseCount(t testing.TB, db *migro.DB, table string, want int64)

AssertDatabaseCount fails unless table has exactly want rows.

func AssertDatabaseHas

func AssertDatabaseHas(t testing.TB, db *migro.DB, table string, where map[string]any)

AssertDatabaseHas fails unless table has a row matching every column in where. A nil value matches NULL.

func AssertDatabaseMissing

func AssertDatabaseMissing(t testing.TB, db *migro.DB, table string, where map[string]any)

AssertDatabaseMissing fails when table has a row matching where.

func AssertNotSoftDeleted

func AssertNotSoftDeleted(t testing.TB, db *migro.DB, table string, where map[string]any)

AssertNotSoftDeleted fails unless a row matching where exists with deleted_at NULL.

func AssertQueryCount

func AssertQueryCount(t testing.TB, db *migro.DB, want int, fn func())

AssertQueryCount runs fn and fails unless it ran exactly want statements.

func AssertSoftDeleted

func AssertSoftDeleted(t testing.TB, db *migro.DB, table string, where map[string]any)

AssertSoftDeleted fails unless a row matching where exists with deleted_at set.

func CountQueries

func CountQueries(db *migro.DB, fn func()) int

CountQueries returns how many statements fn ran on db.

func RefreshDatabase

func RefreshDatabase(t testing.TB, db *migro.DB, migrations []migrate.Migration, opts ...migrate.Option)

RefreshDatabase drops every table and migrates from scratch, so the test starts from a known schema (Laravel's RefreshDatabase). Use it on a database reserved for tests.

func Transaction

func Transaction(t testing.TB, db *migro.DB) *migro.DB

Transaction returns a database inside a transaction that rolls back when the test ends, so each test leaves the data as it found it (Laravel's DatabaseTransactions). DDL that commits implicitly, as on MySQL, escapes the rollback.

Types

This section is empty.

Jump to

Keyboard shortcuts

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