Documentation
¶
Overview ¶
Package dalgotest provides a reusable conformance suite that asserts the record invariants DALgo enforces on the write path.
A storage adapter runs it from its own tests:
func TestConformance(t *testing.T) {
dalgotest.RunConformance(t, func(t *testing.T) (dal.DB, func()) {
return myadapter.NewDB(), nil
})
}
The suite is behavioural: it writes through a live database and asserts what a caller observes. It is the backstop for invariants the framework write pipeline cannot express by construction, and the thing that turns a divergence between two adapters from a silent difference into a failing build.
An adapter that cannot perform a write at all (a read-only or stub adapter) still conforms: the suite accepts dal.ErrNotSupported and dal.ErrNotImplementedYet where it expects a write to succeed. What it never accepts is a storage error where a validation error was due — which is exactly what a non-validating adapter produces.
AssertUniqueKeys is the read-side counterpart: an adapter's tests hand it the records of one read and it fails when two of them share a key.
Index ¶
Constants ¶
const DefaultCollection = "dalgotest_conformance"
DefaultCollection is where conformance records are written unless WithCollection says otherwise.
Variables ¶
var ErrInvalidRecord = errors.New("dalgotest: conformance record is invalid")
ErrInvalidRecord is returned by Record.Validate for a record the suite means to be rejected. Checks assert on it with errors.Is, so an adapter that happens to fail for an unrelated reason does not pass by accident.
Functions ¶
func AssertUniqueKeys ¶ added in v0.95.0
AssertUniqueKeys fails t when two records of one read share a key.
The invariant every provider keeps: within one read (one result set of one query against one recordset) no two records have the same key. The only records allowed to repeat are those with no key at all (see HasNoKey). A provider with no key of its own for a row, such as one of a view, a join or a GROUP BY, keys the rows by ordinal, the position of the row in the read counted from 0 and written as decimal text, which is unique by construction.
Keys are compared as text, with their parents and collections: the integer 1 and the string "1" are one key, as they are one path.
func CheckUniqueKeys ¶ added in v0.95.0
CheckUniqueKeys is AssertUniqueKeys returning the violation, naming both rows (by their position in records, from 0) and the key they share, or nil.
Types ¶
type Check ¶
Check is one named conformance assertion. Run returns nil when the database conforms and a descriptive error when it does not.
Checks is exported alongside RunConformance so that a harness can assert a deliberately non-conforming database FAILS the suite. A conformance suite that cannot detect a non-conforming adapter does nothing, which is the failure mode this package exists to remove one layer down.
type Factory ¶
Factory creates a database for a single conformance check. It returns the database and an optional cleanup function.
An adapter that needs an external resource (a Firestore emulator, a SQL server) calls t.Skip from inside the factory when the resource is absent, so the suite is runnable everywhere and meaningful where the resource exists.
type Option ¶
type Option func(*options)
Option configures the conformance suite.
func WithCollection ¶
WithCollection sets the collection conformance records are written to, for adapters whose schema restricts collection names.