contract

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package contract provides shared test contracts that every Warden store backend must satisfy. Backends import this package from their _test.go files and call the exported `Run*` functions with a factory that builds a fresh store. The contract is the source of truth for "what a Warden store has to do, regardless of backend."

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunAutoIDContract

func RunAutoIDContract(t *testing.T, mk MakeStore)

RunAutoIDContract runs every `Create*` method against a Store constructed by mk and asserts the auto-ID + auto-timestamp behavior:

  • When the input's ID is nil, Create assigns a fresh typeid with the right prefix and the caller's pointer reflects it.
  • When the input's ID is pre-set, Create preserves it.
  • When the input's CreatedAt / UpdatedAt is zero, Create assigns `time.Now().UTC()` (within ±5s of the test's wall clock).
  • When CreatedAt / UpdatedAt is pre-set, Create preserves it.

All assertions are independent — a failure in one entity doesn't stop the suite. Each sub-test uses t.Run so backends can target a single entity with `-run TestAutoID/Role`.

func RunUniquenessContract

func RunUniquenessContract(t *testing.T, mk MakeStore)

RunUniquenessContract asserts the documented uniqueness invariant across every entity type a Warden store persists:

  • Two entities sharing (tenant_id, namespace_path, slug|name) are rejected with the matching ErrDuplicate* sentinel.
  • Same slug|name across different namespaces is allowed.
  • Same slug|name across different tenants is allowed.

Backends call this from their own test files with a MakeStore factory (see autoid.go for the same pattern). Each subtest gets its own fresh store via the factory so tests don't interfere.

Types

type MakeStore

type MakeStore func(t *testing.T) (s store.Store, cleanup func())

MakeStore returns a fresh Store + a cleanup function. The cleanup runs even if the test fails. Backends that talk to a real database (postgres, mongo) typically wrap each call in its own database / collection / schema so tests stay isolated.

Jump to

Keyboard shortcuts

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