Documentation
¶
Overview ¶
Package storetest provides importable in-memory implementations of pkg/store interfaces used across HAIStack tests.
Implemented contracts ¶
- ResourceStore (strict and lenient read semantics)
- HistoryStore, EventStore, CursorStore, InboxStore
- ConflictStore, SearchStore, AuditStore
- WriteSessionProvider (resource + history + search + events)
Resource IDs are returned in stable lexical order. WriteSessionProvider snapshots all four stores and publishes them together on Commit; Rollback discards the session snapshot.
Job persistence reuses jobs.NewInMemoryJobStore via Backend.Jobs rather than duplicating another mem job implementation.
Backend bundles ¶
- NewDeviceBackend — lenient ResourceStore reads (nil, nil on missing) for sync device nodes
- NewStrictBackend — strict ResourceStore reads (error on missing) for core/store tests
- NewWriteSessionProvider — isolated write-session bundle for core integration tests
Strict vs lenient reads ¶
pkg/store/store_test.go and pkg/core tests expect strict semantics: Read returns an error when a resource is absent. pkg/sync device tests expect lenient semantics: Read returns nil, nil. Choose the constructor that matches the scenario.
Compile-time interface checks are declared on each exported store type.
Index ¶
- func ResourceKey(resourceType, id string) stringdeprecated
- type AuditStore
- type Backend
- type ConflictStore
- func (s *ConflictStore) Append(_ context.Context, record store.ConflictRecord) error
- func (s *ConflictStore) List(_ context.Context, resourceType, resourceID string) ([]store.ConflictRecord, error)
- func (s *ConflictStore) Records() []store.ConflictRecord
- func (s *ConflictStore) Resolve(_ context.Context, id string, resolvedAt time.Time) error
- type CursorStore
- type EventStore
- func (s *EventStore) Append(_ context.Context, event store.ResourceEvent) (store.ResourceEvent, error)
- func (s *EventStore) Events() []store.ResourceEvent
- func (s *EventStore) LatestForResource(_ context.Context, resourceType, id string) (*store.ResourceEvent, error)
- func (s *EventStore) ReadSince(_ context.Context, afterSequence int64, limit int) ([]store.ResourceEvent, error)
- type HistoryStore
- func (s *HistoryStore) AppendVersion(_ context.Context, version store.ResourceVersion) error
- func (s *HistoryStore) GetHistory(_ context.Context, resourceType, id string) ([]store.ResourceVersion, error)
- func (s *HistoryStore) GetVersion(_ context.Context, resourceType, id, versionID string) (store.ResourceVersion, error)
- type InboxStore
- type ResourceStore
- func (s *ResourceStore) All() []*types.ResourceEnvelope
- func (s *ResourceStore) Create(_ context.Context, res *types.ResourceEnvelope) error
- func (s *ResourceStore) Delete(_ context.Context, resourceType, id string) error
- func (s *ResourceStore) Exists(_ context.Context, resourceType, id string) (bool, error)
- func (s *ResourceStore) ListIDs(_ context.Context, resourceType string, limit, offset int) ([]string, error)
- func (s *ResourceStore) Read(_ context.Context, resourceType, id string) (*types.ResourceEnvelope, error)
- func (s *ResourceStore) Seed(ctx context.Context, resources ...*types.ResourceEnvelope) error
- func (s *ResourceStore) Update(_ context.Context, res *types.ResourceEnvelope) error
- type SearchStore
- func (s *SearchStore) FieldValues(_ context.Context, resourceType, fieldKey string, resourceIDs []string) (map[string]string, error)
- func (s *SearchStore) Index(_ context.Context, entry store.SearchIndexEntry) error
- func (s *SearchStore) Lookup(_ context.Context, key, value string) ([]string, error)
- func (s *SearchStore) LookupMatch(_ context.Context, match store.SearchMatch) ([]string, error)
- func (s *SearchStore) QueryPrepared(_ context.Context, query store.PreparedQuery, args map[string]string) ([]string, error)
- func (s *SearchStore) RemoveIndex(_ context.Context, resourceType, id string) error
- type WriteSessionProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResourceKey
deprecated
Types ¶
type AuditStore ¶
type AuditStore struct {
// contains filtered or unexported fields
}
AuditStore is an append-only in-memory AuditStore.
func NewAuditStore ¶
func NewAuditStore() *AuditStore
NewAuditStore returns an empty in-memory audit store.
func (*AuditStore) Append ¶
func (s *AuditStore) Append(_ context.Context, record store.AuditRecord) error
func (*AuditStore) List ¶
func (s *AuditStore) List(_ context.Context, query store.AuditQuery) ([]store.AuditRecord, error)
func (*AuditStore) Records ¶
func (s *AuditStore) Records() []store.AuditRecord
Records returns all stored audit records.
type Backend ¶
type Backend struct {
Resources *ResourceStore
History *HistoryStore
Events *EventStore
Cursors *CursorStore
Inbox *InboxStore
Conflicts *ConflictStore
Search *SearchStore
Audit *AuditStore
Jobs *jobs.InMemoryJobStore
}
Backend bundles in-memory stores for a coherent fake device or hub node.
func NewDeviceBackend ¶
func NewDeviceBackend() *Backend
NewDeviceBackend returns a backend configured for sync device nodes (lenient reads).
func NewStrictBackend ¶
func NewStrictBackend() *Backend
NewStrictBackend returns a backend with strict resource store semantics.
type ConflictStore ¶
type ConflictStore struct {
// contains filtered or unexported fields
}
ConflictStore is an in-memory ConflictStore with resource indexing.
func NewConflictStore ¶
func NewConflictStore() *ConflictStore
NewConflictStore returns an empty in-memory conflict store.
func (*ConflictStore) Append ¶
func (s *ConflictStore) Append(_ context.Context, record store.ConflictRecord) error
func (*ConflictStore) List ¶
func (s *ConflictStore) List(_ context.Context, resourceType, resourceID string) ([]store.ConflictRecord, error)
func (*ConflictStore) Records ¶
func (s *ConflictStore) Records() []store.ConflictRecord
Records returns all stored conflict records.
type CursorStore ¶
type CursorStore struct {
// contains filtered or unexported fields
}
CursorStore is an in-memory CursorStore.
func NewCursorStore ¶
func NewCursorStore() *CursorStore
NewCursorStore returns an empty in-memory cursor store.
func (*CursorStore) DeleteCursor ¶
func (s *CursorStore) DeleteCursor(_ context.Context, name string) error
func (*CursorStore) UpsertCursor ¶
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore is an in-memory EventStore with monotonic sequence assignment.
func NewEventStore ¶
func NewEventStore() *EventStore
NewEventStore returns an empty in-memory event store.
func (*EventStore) Append ¶
func (s *EventStore) Append(_ context.Context, event store.ResourceEvent) (store.ResourceEvent, error)
func (*EventStore) Events ¶
func (s *EventStore) Events() []store.ResourceEvent
Events returns a copy of all stored events.
func (*EventStore) LatestForResource ¶
func (s *EventStore) LatestForResource(_ context.Context, resourceType, id string) (*store.ResourceEvent, error)
func (*EventStore) ReadSince ¶
func (s *EventStore) ReadSince(_ context.Context, afterSequence int64, limit int) ([]store.ResourceEvent, error)
type HistoryStore ¶
type HistoryStore struct {
// contains filtered or unexported fields
}
HistoryStore is an in-memory HistoryStore.
func NewHistoryStore ¶
func NewHistoryStore() *HistoryStore
NewHistoryStore returns an empty in-memory history store.
func (*HistoryStore) AppendVersion ¶
func (s *HistoryStore) AppendVersion(_ context.Context, version store.ResourceVersion) error
func (*HistoryStore) GetHistory ¶
func (s *HistoryStore) GetHistory(_ context.Context, resourceType, id string) ([]store.ResourceVersion, error)
func (*HistoryStore) GetVersion ¶
func (s *HistoryStore) GetVersion(_ context.Context, resourceType, id, versionID string) (store.ResourceVersion, error)
type InboxStore ¶
type InboxStore struct {
// contains filtered or unexported fields
}
InboxStore is an in-memory InboxStore.
func NewInboxStore ¶
func NewInboxStore() *InboxStore
NewInboxStore returns an empty in-memory inbox store.
func (*InboxStore) MarkApplied ¶
type ResourceStore ¶
type ResourceStore struct {
// contains filtered or unexported fields
}
ResourceStore is an in-memory ResourceStore. Use NewResourceStore for strict semantics (errors on missing resources) or NewLenientResourceStore for sync device nodes that return nil,nil on Read when a resource is absent.
func NewLenientResourceStore ¶
func NewLenientResourceStore() *ResourceStore
NewLenientResourceStore returns an in-memory resource store that returns nil,nil from Read when a resource is not found (sync device semantics).
func NewResourceStore ¶
func NewResourceStore() *ResourceStore
NewResourceStore returns a strict in-memory resource store.
func (*ResourceStore) All ¶
func (s *ResourceStore) All() []*types.ResourceEnvelope
All returns a snapshot of stored resources.
func (*ResourceStore) Create ¶
func (s *ResourceStore) Create(_ context.Context, res *types.ResourceEnvelope) error
func (*ResourceStore) Delete ¶
func (s *ResourceStore) Delete(_ context.Context, resourceType, id string) error
func (*ResourceStore) Read ¶
func (s *ResourceStore) Read(_ context.Context, resourceType, id string) (*types.ResourceEnvelope, error)
func (*ResourceStore) Seed ¶
func (s *ResourceStore) Seed(ctx context.Context, resources ...*types.ResourceEnvelope) error
Seed creates resources and returns the first insertion error.
func (*ResourceStore) Update ¶
func (s *ResourceStore) Update(_ context.Context, res *types.ResourceEnvelope) error
type SearchStore ¶
type SearchStore struct {
// contains filtered or unexported fields
}
SearchStore is an in-memory SearchStore with basic field lookup.
func NewSearchStore ¶
func NewSearchStore() *SearchStore
NewSearchStore returns an empty in-memory search store.
func (*SearchStore) FieldValues ¶
func (s *SearchStore) FieldValues(_ context.Context, resourceType, fieldKey string, resourceIDs []string) (map[string]string, error)
FieldValues returns indexed values for the requested resource IDs.
func (*SearchStore) Index ¶
func (s *SearchStore) Index(_ context.Context, entry store.SearchIndexEntry) error
func (*SearchStore) LookupMatch ¶
func (s *SearchStore) LookupMatch(_ context.Context, match store.SearchMatch) ([]string, error)
LookupMatch returns IDs matching one typed field predicate. It implements store.SearchQueryExecutor so the same fake can back both search.Service and core.ResourceService in an integration harness.
func (*SearchStore) QueryPrepared ¶
func (s *SearchStore) QueryPrepared(_ context.Context, query store.PreparedQuery, args map[string]string) ([]string, error)
func (*SearchStore) RemoveIndex ¶
func (s *SearchStore) RemoveIndex(_ context.Context, resourceType, id string) error
type WriteSessionProvider ¶
type WriteSessionProvider struct {
Resources *ResourceStore
History *HistoryStore
Search *SearchStore
Events *EventStore
// contains filtered or unexported fields
}
WriteSessionProvider provides atomic write sessions over resource, history, search, and events.
func NewWriteSessionProvider ¶
func NewWriteSessionProvider() *WriteSessionProvider
NewWriteSessionProvider returns a write session provider with fresh stores.
func (*WriteSessionProvider) BeginWrite ¶
func (p *WriteSessionProvider) BeginWrite(_ context.Context) (store.WriteSession, error)