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 ¶
- func AssertCount(t testing.TB, ctx context.Context, executor database.Executor, query Query, ...)
- func AssertExists(t testing.TB, ctx context.Context, executor database.Executor, query Query)
- func AssertMissing(t testing.TB, ctx context.Context, executor database.Executor, query Query)
- func AssertSoftDeleted[Q Trashable[Q]](t testing.TB, ctx context.Context, executor database.Executor, query Q)
- func AssertStatementShapes(t testing.TB, scope *database.StatementScope)
- type Query
- type Trashable
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 ¶
AssertExists requires at least one row matched by query.
func AssertMissing ¶
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.