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 RunNamespaceFilterContract ¶ added in v1.5.3
RunNamespaceFilterContract asserts that the namespace-scoped list queries on the Check() hot path correctly filter by a multi-element slice of namespace paths.
This is the regression contract for the bug where the SQL stores wrote:
q.Where("namespace_path IN (?)", namespacePaths) // namespacePaths is []string
Grove's query builders bind one argument per "?" placeholder and do not expand slices, so the whole []string was bound to the single "?" and the driver (pgx / sqlite) rejected it — every Check() against a SQL store errored. The fix: postgres uses WhereArray("= ANY"); sqlite expands to IN (?, ?, …). The in-memory store iterates in Go and always satisfied this; this contract guards the SQL backends so the bug can't come back.
Each case seeds rows across the ancestor namespaces ["eng/platform", "eng", ""] plus one decoy row at a non-ancestor "other" namespace that must be excluded from the result.
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.