Documentation
¶
Overview ¶
Package fabriqtest is fabriq's exported test kit.
Package fabriqtest is fabriq's exported test kit: in-memory fakes for every port, a combined World wiring them over shared memory, and (in later phases) the testcontainers harness and seeded fixtures.
Downstream services unit-test against these fakes; the same behavioral contracts are enforced on real adapters by the integration suites.
Index ¶
- Constants
- Variables
- func CreateAppRole(t testing.TB, superDSN string) string
- func NewConformanceBackend(t testing.TB) conformance.Backend
- func NewFabric(w *World) query.Fabric
- func RunCacheConformance(t *testing.T, newCache func(t *testing.T) cache.Cache)
- func StartElasticsearch(t testing.TB) string
- func StartFalkorDB(t testing.TB) string
- func StartPostgres(t testing.TB) string
- func StartRedis(t testing.TB) string
- type FakeBlob
- func (f *FakeBlob) Capabilities() blob.Caps
- func (f *FakeBlob) Copy(ctx context.Context, srcKey, dstKey string) (blob.ObjectInfo, error)
- func (f *FakeBlob) Delete(ctx context.Context, key string) error
- func (f *FakeBlob) Get(ctx context.Context, key string) (io.ReadCloser, blob.ObjectInfo, error)
- func (f *FakeBlob) Head(ctx context.Context, key string) (blob.ObjectInfo, error)
- func (f *FakeBlob) List(ctx context.Context, prefix string) ([]blob.ObjectInfo, error)
- func (f *FakeBlob) Put(ctx context.Context, key string, r io.Reader, o blob.PutOpts) (blob.ObjectInfo, error)
- type FakeCAS
- type FakeCache
- func (c *FakeCache) Close() error
- func (c *FakeCache) Get(ctx context.Context, ks cache.Keyspace, key string) (val []byte, ok bool, err error)
- func (c *FakeCache) GetOrLoad(ctx context.Context, ks cache.Keyspace, key string, ...) ([]byte, error)
- func (c *FakeCache) Invalidate(ctx context.Context, ks cache.Keyspace, keys ...string) error
- func (c *FakeCache) InvalidateEntity(ctx context.Context, entity string) error
- func (c *FakeCache) InvalidateKeyspace(ctx context.Context, ks cache.Keyspace) error
- func (c *FakeCache) Set(ctx context.Context, ks cache.Keyspace, key string, val []byte) error
- type FakeDocumentStore
- func (f *FakeDocumentStore) ApplyUpdate(context.Context, string, []byte) error
- func (f *FakeDocumentStore) Compact(context.Context, string) error
- func (f *FakeDocumentStore) Snapshot(context.Context, string) (document.Materialized, error)
- func (f *FakeDocumentStore) Sync(context.Context, string, []byte) ([]byte, error)
- type FakeGraph
- func (g *FakeGraph) ApplyMutations(ctx context.Context, target string, muts []projection.Mutation) error
- func (g *FakeGraph) Cann(cypher string, ids []string)
- func (g *FakeGraph) HasEdge(target, rel, fromLabel, fromID, toLabel, toID string) bool
- func (g *FakeGraph) Node(target, label, id string) (FakeNode, bool)
- func (g *FakeGraph) Query(_ context.Context, cypher string, _ map[string]any, into any) error
- func (g *FakeGraph) TraverseAndHydrate(ctx context.Context, cypher string, params map[string]any, into any) error
- type FakeNode
- type FakeProjectionState
- type FakeRelational
- func (r *FakeRelational) Get(ctx context.Context, entity, id string, into any) error
- func (r *FakeRelational) GetMany(ctx context.Context, entity string, ids []string, into any) error
- func (r *FakeRelational) List(ctx context.Context, entity string, q query.ListQuery, into any) error
- func (r *FakeRelational) Query(context.Context, any, string, ...any) error
- type FakeSearch
- type FakeSpatial
- type FakeStore
- type FakeTS
- type FakeVector
- type World
Constants ¶
const ( PostgresImage = "timescale/timescaledb-ha:pg16-all" RedisImage = "redis:7-alpine" FalkorDBImage = "falkordb/falkordb:v4.2.2" // pinned: multi-label + SET n:Label ElasticsearchImage = "elasticsearch:9.4.1" )
Container images for the integration harness. timescaledb-ha bundles TimescaleDB and pgvector, matching the production datastore contract.
Variables ¶
var ErrFakeNotFound = fabriqerr.ErrNotFound
ErrFakeNotFound is the not-found error returned by fakes; it is the canonical fabriq ErrNotFound so errors.Is works either way.
Functions ¶
func CreateAppRole ¶
CreateAppRole provisions a NON-superuser application role on a database previously started with StartPostgres and returns a DSN for it.
This mirrors production: migrations run as the schema owner; the application connects as a restricted role so RLS actually applies (Postgres row security NEVER constrains superusers). Call it AFTER running migrations.
func NewConformanceBackend ¶
func NewConformanceBackend(t testing.TB) conformance.Backend
NewConformanceBackend builds a fake-backed conformance.Backend over the domain registry. It is the fast (Docker-free) gate that keeps the fakes from drifting from real-adapter behavior.
func NewFabric ¶
NewFabric returns a query.Fabric backed by the World's in-memory fakes. Exec runs through a command.Executor on the World's store (so writes are visible through Relational). Subscribe returns a fresh buffered channel (no deltas are published unless a test drives the underlying fakes); WaitForProjection is a no-op.
func RunCacheConformance ¶
RunCacheConformance is the single behavioral contract for cache.Cache. It is run against FakeCache (unit) and the grove-kv adapter (integration) so the two can never drift. newCache returns a fresh, empty cache per subtest.
func StartElasticsearch ¶
StartElasticsearch launches a single-node Elasticsearch container (security off, HTTP only) and returns its base URL. The container terminates with the test.
func StartFalkorDB ¶
StartFalkorDB launches a FalkorDB container and returns its address (host:port). The container terminates with the test.
func StartPostgres ¶
StartPostgres launches a Postgres+Timescale+pgvector container and returns its DSN. The container terminates with the test.
func StartRedis ¶
StartRedis launches a Redis container and returns its address (host:port). The container terminates with the test.
Types ¶
type FakeBlob ¶
type FakeBlob struct {
// contains filtered or unexported fields
}
FakeBlob is an in-memory, tenant-scoped blob.Store for tests. It implements only the core Store surface — no capability sub-interfaces — so Caps reports all false and capability-gated conformance cases skip.
func (*FakeBlob) Capabilities ¶
func (*FakeBlob) Get ¶
func (f *FakeBlob) Get(ctx context.Context, key string) (io.ReadCloser, blob.ObjectInfo, error)
type FakeCAS ¶
type FakeCAS struct {
// contains filtered or unexported fields
}
FakeCAS is an in-memory content-addressed store for hermetic tests. It implements blob.CAS, dedups by sha256, and is tenant-agnostic.
type FakeCache ¶
type FakeCache struct {
// contains filtered or unexported fields
}
FakeCache is an in-memory cache.Cache for unit tests. It implements the same behavioral contract (RunCacheConformance) as the real grove-kv adapter: scope isolation, generation invalidation, single-flight GetOrLoad, TTL.
func (*FakeCache) Invalidate ¶
func (*FakeCache) InvalidateEntity ¶
InvalidateEntity bumps the entity generation for Global + Tenant + (if present) TenantScope partitions, mirroring the adapter.
func (*FakeCache) InvalidateKeyspace ¶
type FakeDocumentStore ¶
type FakeDocumentStore struct{}
FakeDocumentStore is the deferred document plane: every method states the plane is not implemented yet (phase 7).
func (*FakeDocumentStore) ApplyUpdate ¶
ApplyUpdate implements document.Store (deferred).
func (*FakeDocumentStore) Compact ¶
func (f *FakeDocumentStore) Compact(context.Context, string) error
Compact implements document.Store (deferred).
func (*FakeDocumentStore) Snapshot ¶
func (f *FakeDocumentStore) Snapshot(context.Context, string) (document.Materialized, error)
Snapshot implements document.Store (deferred).
type FakeGraph ¶
type FakeGraph struct {
// contains filtered or unexported fields
}
FakeGraph applies engine-neutral mutations to an in-memory property graph with the same version gating real adapters implement, and serves canned responses for raw Cypher (fakes do not parse Cypher).
func NewFakeGraph ¶
func NewFakeGraph(reg *registry.Registry, rel query.RelationalQuerier) *FakeGraph
NewFakeGraph builds a graph fake hydrating through rel.
func (*FakeGraph) ApplyMutations ¶
func (g *FakeGraph) ApplyMutations(ctx context.Context, target string, muts []projection.Mutation) error
ApplyMutations implements the projection write path with version gating. target "" resolves to the tenant's live graph (tenant from ctx), the same contract real sinks implement.
type FakeProjectionState ¶
type FakeProjectionState struct {
// contains filtered or unexported fields
}
FakeProjectionState tracks applied versions per aggregate for WaitForProjection tests; projection consumers (or tests) advance it with SetApplied.
func (*FakeProjectionState) AppliedVersion ¶
func (f *FakeProjectionState) AppliedVersion(_ context.Context, tenantID, proj, aggregate, aggID string) (int64, error)
AppliedVersion implements projection.StateReader.
func (*FakeProjectionState) SetApplied ¶
func (f *FakeProjectionState) SetApplied(_ context.Context, tenantID, proj, aggregate, aggID string, version int64) error
SetApplied records that a projection has applied an aggregate version (implements projection.AppliedRecorder; the watermark never regresses).
type FakeRelational ¶
type FakeRelational struct {
// contains filtered or unexported fields
}
FakeRelational reads the world's shared memory, tenant-scoped from ctx.
func (*FakeRelational) GetMany ¶
GetMany implements the batched hydration contract: one logical lookup, results in ids order, missing ids skipped.
type FakeSearch ¶
type FakeSearch struct {
// contains filtered or unexported fields
}
FakeSearch is a substring-matching search fake with version gating and ctx-tenant scoping.
func NewFakeSearch ¶
func NewFakeSearch(reg *registry.Registry) *FakeSearch
NewFakeSearch builds a search fake.
func (*FakeSearch) ApplyMutations ¶
func (s *FakeSearch) ApplyMutations(_ context.Context, _ string, muts []projection.Mutation) error
ApplyMutations implements the projection write path.
func (*FakeSearch) Search ¶
func (s *FakeSearch) Search(ctx context.Context, q query.SearchQuery, into any) error
Search implements substring match over the entity's declared fields, narrowed by the structured Filter, ordered by Sort (id when empty, since the fake has no relevance score) and paginated by Offset/Limit. It mirrors the ES adapter's neutral contract closely enough for unit tests; the integration suite is the source of truth for scoring and analysis.
type FakeSpatial ¶
type FakeSpatial struct {
// contains filtered or unexported fields
}
FakeSpatial is an exact in-memory geometry store that implements query.SpatialQuerier. It is tenant-scoped via ctx and safe for concurrent use. Distance computation is haversine for SRID 4326, planar Euclidean otherwise.
func (*FakeSpatial) Delete ¶
func (f *FakeSpatial) Delete(ctx context.Context, entity, id string) error
Delete implements query.SpatialQuerier.
func (*FakeSpatial) Upsert ¶
func (f *FakeSpatial) Upsert(ctx context.Context, entity, id string, geom query.Geometry, meta map[string]any) error
Upsert implements query.SpatialQuerier.
func (*FakeSpatial) Within ¶
func (f *FakeSpatial) Within(ctx context.Context, q query.SpatialQuery, into any) error
Within implements query.SpatialQuerier. Results are scanned into *[]query.SpatialMatch, nearest-first; ties break by ID.
type FakeStore ¶
type FakeStore struct {
// contains filtered or unexported fields
}
FakeStore implements command.Store with real transactional semantics: changes stage into a snapshot and merge only on success, so batch atomicity behaves like the Postgres adapter.
func (*FakeStore) FailOnOutbox ¶
FailOnOutbox injects an outbox failure (nil to clear).
type FakeTS ¶
type FakeTS struct {
// contains filtered or unexported fields
}
FakeTS stores points per (tenant, series, key), time-sorted.
type FakeVector ¶
type FakeVector struct {
// contains filtered or unexported fields
}
FakeVector is an exact cosine-similarity store.
func (*FakeVector) Delete ¶
func (f *FakeVector) Delete(ctx context.Context, entity, id string) error
Delete implements query.VectorQuerier.
func (*FakeVector) Similar ¶
func (f *FakeVector) Similar(ctx context.Context, q query.VectorQuery, into any) error
Similar implements exact top-K cosine search.
type World ¶
type World struct {
Registry *registry.Registry
Store *FakeStore
Rel *FakeRelational
Graph *FakeGraph
Search *FakeSearch
TS *FakeTS
Vector *FakeVector
Spatial *FakeSpatial
Docs *FakeDocumentStore
Projections *FakeProjectionState
Blob *FakeBlob
}
World wires all fakes over one shared in-memory store, so a command executed against Store is immediately visible through Rel, and graph / search fakes can hydrate from the same rows.