storetest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResourceKey deprecated

func ResourceKey(resourceType, id string) string

ResourceKey returns the canonical map key for a FHIR resource type and id.

Deprecated: use testkit.ResourceKey. This compatibility wrapper keeps older storetest consumers source-compatible while maintaining one implementation.

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 (*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.

func (*ConflictStore) Resolve

func (s *ConflictStore) Resolve(_ context.Context, id string, resolvedAt time.Time) error

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

func (s *CursorStore) GetCursor(_ context.Context, name string) (*store.Cursor, error)

func (*CursorStore) UpsertCursor

func (s *CursorStore) UpsertCursor(_ context.Context, cursor store.Cursor) error

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 (*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) AppliedAt

func (s *InboxStore) AppliedAt(_ context.Context, id string) (*time.Time, error)

func (*InboxStore) IsApplied

func (s *InboxStore) IsApplied(_ context.Context, id string) (bool, error)

func (*InboxStore) MarkApplied

func (s *InboxStore) MarkApplied(_ context.Context, id string, appliedAt time.Time) error

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 (*ResourceStore) Delete

func (s *ResourceStore) Delete(_ context.Context, resourceType, id string) error

func (*ResourceStore) Exists

func (s *ResourceStore) Exists(_ context.Context, resourceType, id string) (bool, error)

func (*ResourceStore) ListIDs

func (s *ResourceStore) ListIDs(_ context.Context, resourceType string, limit, offset int) ([]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

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 (*SearchStore) Lookup

func (s *SearchStore) Lookup(_ context.Context, key, value string) ([]string, 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

Jump to

Keyboard shortcuts

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