Documentation
¶
Overview ¶
Package dbtest supplies isolated PostgreSQL clones for database-backed tests. A suite owns its template and accepts initialization from the schema's owner.
Index ¶
- func Count(t testing.TB, db *database.DB, want int, q string, args ...any)
- func FailNextStatement(t testing.TB, db *database.DB, fragment string)
- func Restore(ctx context.Context, db *database.DB, schemaSQL string, rows []Row) error
- func Shape(ctx context.Context, db *database.DB) (string, error)
- func WaitForLock(t testing.TB, db *database.DB, query string)
- func WriteRows(path string, rows []Row) error
- type Row
- type Suite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Count ¶
Count fails the test unless q, a single-count query, answers want. It is for storage tests whose guarantee is the stored representation; tests of behaviour ask the owner instead.
func FailNextStatement ¶
FailNextStatement makes the next statement whose text contains fragment fail, for the rest of the test: the fault a test injects to prove a failed write or read is reported, never mistaken for success.
func Restore ¶
Restore makes db hold a release's database: its public schema emptied, the release's own schema run, and its rows put back with triggers, foreign-key checks among them, switched off while they load (session_replication_role). That is a load exemption, not a deferral: nothing checks the rows afterwards, so they must be what Snapshot read from a consistent database. A generated column is left to compute itself.
func Shape ¶
Shape is a database's public schema as text: every column with its type, nullability, default and generation; every constraint with its definition; every index with its definition. Two databases with the same Shape have the same schema, whatever order their objects were made in.
func WaitForLock ¶
WaitForLock observes that the named statement is blocked in PostgreSQL. Tests use it to order concurrent operations without guessing a sleep duration.
Types ¶
type Row ¶
type Row struct {
Table string `json:"table"`
Row json.RawMessage `json:"row"`
}
Row is one table row as a release left it: the table and the row as JSON (row_to_json), so a later build can put it back without that release's code.
type Suite ¶
type Suite struct {
// contains filtered or unexported fields
}