dalgotest

package
v0.64.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
const DefaultCollection = "dalgotest_conformance"

DefaultCollection is where conformance records are written unless WithCollection says otherwise.

Variables

View Source
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 RunConformance

func RunConformance(t *testing.T, newDB Factory, opts ...Option)

RunConformance runs every check against a fresh database from newDB, one subtest per check.

Types

type Check

type Check struct {
	Name string
	Run  func(ctx context.Context, db dal.DB) error
}

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.

func Checks

func Checks(opts ...Option) []Check

Checks returns the conformance checks.

type Factory

type Factory func(t *testing.T) (db dal.DB, cleanup func())

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

func WithCollection(name string) Option

WithCollection sets the collection conformance records are written to, for adapters whose schema restricts collection names.

type Plain

type Plain struct {
	Name string `json:"name"`
}

Plain is record data that deliberately does not implement dal.ValidatableRecord, used to prove enforcement does not affect models that declare no invariants.

type Record

type Record struct {
	Name string `json:"name"`
}

Record is the record data the suite writes. It is invalid when Name is empty, so the validity of a fixture is visible in its literal.

func (Record) Validate

func (r Record) Validate() error

Validate implements dal.ValidatableRecord.

Jump to

Keyboard shortcuts

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