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