clienttest

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package clienttest provides an in-memory writer model implementing client.Hooks over a client.MemStore, for tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEpisode = errors.New("clienttest: no open episode")

ErrNoEpisode reports a transition for a key without an open episode.

Functions

This section is empty.

Types

type Capture

type Capture struct {
	Epoch      protocol.EpochID
	Watermark  uint64
	Committed  uint64
	AnchorHash protocol.Hash
	Summary    protocol.SummaryParams
}

Capture records one replay capture.

type Clock

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

Clock is a settable clock shared by a writer and its store.

func NewClock

func NewClock(t time.Time) *Clock

NewClock returns a clock at t.

func (*Clock) Advance

func (c *Clock) Advance(d time.Duration)

Advance moves the clock forward.

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the current time.

type Episode

type Episode struct {
	ID             string
	DedupKey       string
	State          string
	FirstSeen      uint64
	LastTransition uint64
	EvalTime       uint64
	Count          uint64
	Seq            uint64
}

Episode is one finding episode.

type StateQueryResult

type StateQueryResult struct {
	Source    string   `json:"source"`
	Resources []string `json:"resources"`
	Truncated bool     `json:"truncated"`
}

StateQueryResult is the state.query result.

type Writer

type Writer struct {
	Store *client.MemStore
	Clock *Clock
	// AnchorMutator, when set, alters the state written into replay anchors.
	AnchorMutator func(*protocol.State)
	// OnBundle, when set, is called for every bundle.available.
	OnBundle func(protocol.BundleAvailableParams)
	// contains filtered or unexported fields
}

Writer is the writer model. Every mutation runs inside Store.Do, so captures are atomic with it.

func NewWriter

func NewWriter(store *client.MemStore, clock *Clock) *Writer

NewWriter returns an empty writer model on store.

func (*Writer) Apply

func (w *Writer) Apply(ops ...protocol.Op) (uint64, error)

Apply appends one delta with ops and returns its sequence.

func (*Writer) BundleAvailable

func (w *Writer) BundleAvailable(p protocol.BundleAvailableParams)

BundleAvailable records the announcement.

func (*Writer) Bundles

func (w *Writer) Bundles() []protocol.BundleAvailableParams

Bundles returns every bundle announcement received.

func (*Writer) CaptureReplay

func (w *Writer) CaptureReplay(tx client.CaptureTx) (protocol.SummaryParams, error)

CaptureReplay appends the replay anchor and returns the summary of findings touched above the committed head.

func (*Writer) Captures

func (w *Writer) Captures() []Capture

Captures returns every replay capture in order.

func (*Writer) Clone

func (w *Writer) Clone(store *client.MemStore) *Writer

Clone copies the model onto store, as a restarted or forked process that rebuilt its state.

func (*Writer) Episodes

func (w *Writer) Episodes() map[string]Episode

Episodes returns every episode by finding ID.

func (*Writer) Fire

func (w *Writer) Fire(key string) (string, uint64, error)

Fire opens a new episode for key and returns its finding ID and sequence.

func (*Writer) Health

func (w *Writer) Health() any

Health reports the spool backlog.

func (*Writer) Rebaseline

func (w *Writer) Rebaseline(tx client.CaptureTx) error

Rebaseline appends the full checkpoint of a new epoch.

func (*Writer) Resolve

func (w *Writer) Resolve(key string) (uint64, error)

Resolve closes the open episode for key.

func (*Writer) State

func (w *Writer) State() *protocol.State

State returns a copy of the current state.

func (*Writer) StateHashes

func (w *Writer) StateHashes(epoch protocol.EpochID) map[uint64]protocol.Hash

StateHashes returns the state hash at every sequence this writer assigned in epoch.

func (*Writer) Tool

func (w *Writer) Tool(_ context.Context, name string, args json.RawMessage) (any, error)

Tool serves state.query.

func (*Writer) Tools

func (w *Writer) Tools() []client.Tool

Tools advertises state.query.

func (*Writer) Update

func (w *Writer) Update(key string) (uint64, error)

Update records an update transition of the open episode for key.

Jump to

Keyboard shortcuts

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