fabriqtest

package
v0.0.2 Latest Latest
Warning

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

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

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

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

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

func CreateAppRole(t testing.TB, superDSN string) string

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

func NewFabric(w *World) query.Fabric

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

func RunCacheConformance(t *testing.T, newCache func(t *testing.T) cache.Cache)

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

func StartElasticsearch(t testing.TB) string

StartElasticsearch launches a single-node Elasticsearch container (security off, HTTP only) and returns its base URL. The container terminates with the test.

func StartFalkorDB

func StartFalkorDB(t testing.TB) string

StartFalkorDB launches a FalkorDB container and returns its address (host:port). The container terminates with the test.

func StartPostgres

func StartPostgres(t testing.TB) string

StartPostgres launches a Postgres+Timescale+pgvector container and returns its DSN. The container terminates with the test.

func StartRedis

func StartRedis(t testing.TB) string

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 NewFakeBlob

func NewFakeBlob() *FakeBlob

NewFakeBlob creates an empty in-memory blob store.

func (*FakeBlob) Capabilities

func (f *FakeBlob) Capabilities() blob.Caps

func (*FakeBlob) Copy

func (f *FakeBlob) Copy(ctx context.Context, srcKey, dstKey string) (blob.ObjectInfo, error)

func (*FakeBlob) Delete

func (f *FakeBlob) Delete(ctx context.Context, key string) error

func (*FakeBlob) Get

func (*FakeBlob) Head

func (f *FakeBlob) Head(ctx context.Context, key string) (blob.ObjectInfo, error)

func (*FakeBlob) List

func (f *FakeBlob) List(ctx context.Context, prefix string) ([]blob.ObjectInfo, error)

func (*FakeBlob) Put

func (f *FakeBlob) Put(ctx context.Context, key string, r io.Reader, o blob.PutOpts) (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.

func NewFakeCAS

func NewFakeCAS() *FakeCAS

NewFakeCAS builds an empty FakeCAS.

func (*FakeCAS) Has

func (c *FakeCAS) Has(hash string) bool

Has reports whether a hash is present.

func (*FakeCAS) Len

func (c *FakeCAS) Len() int

Len returns the number of distinct stored blobs.

func (*FakeCAS) Retrieve

func (c *FakeCAS) Retrieve(_ context.Context, hash string) (io.ReadCloser, error)

Retrieve returns the bytes for a hash.

func (*FakeCAS) Store

func (c *FakeCAS) Store(_ context.Context, r io.Reader) (hash string, size int64, err error)

Store writes content-addressed bytes and returns the sha256 hex hash.

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 NewFakeCache

func NewFakeCache() *FakeCache

NewFakeCache builds an empty in-memory cache.

func (*FakeCache) Close

func (c *FakeCache) Close() error

func (*FakeCache) Get

func (c *FakeCache) Get(ctx context.Context, ks cache.Keyspace, key string) (val []byte, ok bool, err error)

func (*FakeCache) GetOrLoad

func (c *FakeCache) GetOrLoad(ctx context.Context, ks cache.Keyspace, key string,
	load func(context.Context) ([]byte, error)) ([]byte, error)

func (*FakeCache) Invalidate

func (c *FakeCache) Invalidate(ctx context.Context, ks cache.Keyspace, keys ...string) error

func (*FakeCache) InvalidateEntity

func (c *FakeCache) InvalidateEntity(ctx context.Context, entity string) error

InvalidateEntity bumps the entity generation for Global + Tenant + (if present) TenantScope partitions, mirroring the adapter.

func (*FakeCache) InvalidateKeyspace

func (c *FakeCache) InvalidateKeyspace(ctx context.Context, ks cache.Keyspace) error

func (*FakeCache) Set

func (c *FakeCache) Set(ctx context.Context, ks cache.Keyspace, key string, val []byte) error

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

func (f *FakeDocumentStore) ApplyUpdate(context.Context, string, []byte) error

ApplyUpdate implements document.Store (deferred).

func (*FakeDocumentStore) Compact

Compact implements document.Store (deferred).

func (*FakeDocumentStore) Snapshot

Snapshot implements document.Store (deferred).

func (*FakeDocumentStore) Sync

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

func (*FakeGraph) Cann

func (g *FakeGraph) Cann(cypher string, ids []string)

Cann registers the id list a Cypher string returns (exact match).

func (*FakeGraph) HasEdge

func (g *FakeGraph) HasEdge(target, rel, fromLabel, fromID, toLabel, toID string) bool

HasEdge inspects an edge in a target graph.

func (*FakeGraph) Node

func (g *FakeGraph) Node(target, label, id string) (FakeNode, bool)

Node inspects a node in a target graph.

func (*FakeGraph) Query

func (g *FakeGraph) Query(_ context.Context, cypher string, _ map[string]any, into any) error

Query implements query.GraphQuerier for canned traversals.

func (*FakeGraph) TraverseAndHydrate

func (g *FakeGraph) TraverseAndHydrate(ctx context.Context, cypher string, params map[string]any, into any) error

TraverseAndHydrate composes the canned traversal with one batched relational hydration (the no-N+1 contract).

type FakeNode

type FakeNode struct {
	Props   map[string]any
	Version int64
}

FakeNode is an inspectable graph node.

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) Get

func (r *FakeRelational) Get(ctx context.Context, entity, id string, into any) error

Get implements query.RelationalQuerier.

func (*FakeRelational) GetMany

func (r *FakeRelational) GetMany(ctx context.Context, entity string, ids []string, into any) error

GetMany implements the batched hydration contract: one logical lookup, results in ids order, missing ids skipped.

func (*FakeRelational) List

func (r *FakeRelational) List(ctx context.Context, entity string, q query.ListQuery, into any) error

List implements equality-filtered paging.

func (*FakeRelational) Query

func (r *FakeRelational) Query(context.Context, any, string, ...any) error

Query is unsupported in the fake — raw SQL belongs to integration tests against the real adapter.

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

func (s *FakeStore) FailOnOutbox(fn func() error)

FailOnOutbox injects an outbox failure (nil to clear).

func (*FakeStore) InTenantTx

func (s *FakeStore) InTenantTx(ctx context.Context, fn func(ctx context.Context, tx command.Tx) error) error

InTenantTx implements command.Store. Fakes run transactions one at a time; concurrency tests belong to the real adapter's integration suite.

func (*FakeStore) Outbox

func (s *FakeStore) Outbox() []event.Envelope

Outbox returns every envelope committed so far, in order.

type FakeTS

type FakeTS struct {
	// contains filtered or unexported fields
}

FakeTS stores points per (tenant, series, key), time-sorted.

func (*FakeTS) BulkWrite

func (f *FakeTS) BulkWrite(ctx context.Context, series string, points []query.Point) error

BulkWrite implements the event-bypass telemetry ingest.

func (*FakeTS) Range

func (f *FakeTS) Range(ctx context.Context, q query.RangeQuery, into any) error

Range implements raw-point reads over [From, To).

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.

func (*FakeVector) Upsert

func (f *FakeVector) Upsert(ctx context.Context, entity, id string, embedding []float32, meta map[string]any) error

Upsert implements query.VectorQuerier.

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.

func NewWorld

func NewWorld(reg *registry.Registry) *World

NewWorld builds the linked fake set for a registry.

func (*World) Executor

func (w *World) Executor() *command.Executor

Executor returns a command executor wired to the world's store.

Jump to

Keyboard shortcuts

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