dbassert

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dbassert asserts persisted state through typed generated queries. Assertions only read through the supplied executor, usually the test's own transaction; they never reset, truncate or seed data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertCount

func AssertCount(t testing.TB, ctx context.Context, executor database.Executor, query Query, want int64)

AssertCount requires exactly want rows matched by query.

func AssertExists

func AssertExists(t testing.TB, ctx context.Context, executor database.Executor, query Query)

AssertExists requires at least one row matched by query.

func AssertMissing

func AssertMissing(t testing.TB, ctx context.Context, executor database.Executor, query Query)

AssertMissing requires that query matches no rows. Soft-deleted rows are invisible to an ordinary generated query; use AssertSoftDeleted for them.

func AssertSoftDeleted

func AssertSoftDeleted[Q Trashable[Q]](t testing.TB, ctx context.Context, executor database.Executor, query Q)

AssertSoftDeleted requires that query's rows exist only as soft-deleted rows: the ordinary query matches none and its OnlyTrashed variant matches at least one. Pass an ordinary query, not one derived with WithTrashed.

func AssertStatementShapes

func AssertStatementShapes(t testing.TB, scope *database.StatementScope)

AssertStatementShapes asserts a completed test scope stayed within its configured per-shape threshold. Shape or call-site capacity overflow fails rather than silently passing incomplete observations. Close all query rows before asserting. Example: ctx,scope := detector.Begin(t.Context()); run(ctx); dbassert.AssertStatementShapes(t,scope).

Types

type Query

type Query interface {
	Count(context.Context, database.Executor) (int64, error)
	Exists(context.Context, database.Executor) (bool, error)
}

Query is satisfied by native ORM queries and row results. Its model scopes, including soft-delete visibility, apply exactly as they do in application code.

type Trashable

type Trashable[Q any] interface {
	Query
	OnlyTrashed() Q
}

Trashable is a soft-deleting model query deriving its own type.

Jump to

Keyboard shortcuts

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