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.
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 ¶
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.