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 ¶
- func AssertDatabaseCount(t testing.TB, db *migro.DB, table string, want int64)
- func AssertDatabaseHas(t testing.TB, db *migro.DB, table string, where map[string]any)
- func AssertDatabaseMissing(t testing.TB, db *migro.DB, table string, where map[string]any)
- func AssertNotSoftDeleted(t testing.TB, db *migro.DB, table string, where map[string]any)
- func AssertQueryCount(t testing.TB, db *migro.DB, want int, fn func())
- func AssertSoftDeleted(t testing.TB, db *migro.DB, table string, where map[string]any)
- func CountQueries(db *migro.DB, fn func()) int
- func RefreshDatabase(t testing.TB, db *migro.DB, migrations []migrate.Migration, ...)
- func Transaction(t testing.TB, db *migro.DB) *migro.DB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDatabaseCount ¶
AssertDatabaseCount fails unless table has exactly want rows.
func AssertDatabaseHas ¶
AssertDatabaseHas fails unless table has a row matching every column in where. A nil value matches NULL.
func AssertDatabaseMissing ¶
AssertDatabaseMissing fails when table has a row matching where.
func AssertNotSoftDeleted ¶
AssertNotSoftDeleted fails unless a row matching where exists with deleted_at NULL.
func AssertQueryCount ¶
AssertQueryCount runs fn and fails unless it ran exactly want statements.
func AssertSoftDeleted ¶
AssertSoftDeleted fails unless a row matching where exists with deleted_at set.
func CountQueries ¶
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 ¶
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.