Help us shape the future of Go! Take the 2026 Go Developer Survey

storetest

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Overview

Package storetest checks that an agent.Store meets the requirements the journal builds on (A1 to A8, documented on agent.Store), that a Journal over it writes and checks the journal format header, and that records round-trip byte for byte. Every store in this module runs it, and a new backend should too:

func TestStore(t *testing.T) {
    db := openTestDatabase(t)
    storetest.Run(t, func(t *testing.T) agent.Store { return myStoreOn(db) })
}

open may be called several times in one test; every handle it returns must reach the same data (a new connection to the same database, or the same in-memory store), since the suite checks what one handle's writes look like through another. Run IDs are unique per call, so the suite can run repeatedly against a persistent backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckWrapper

func CheckWrapper(t testing.TB, wrap func(agent.Store) agent.Store, ctxs ...context.Context)

CheckWrapper checks a store wrapper against the rules for wrappers (see agent.Store): its mapping of run IDs and names to stored entries does not depend on the context (A1), and it may expose the capabilities of the store it wraps through Unwrap only if it passes run IDs and names through unchanged. wrap wraps the store it is given; CheckWrapper wraps a MemStore, which implements Lister and Leaser.

ctxs are at least two contexts the wrapper will be called with, and they must differ in the values the wrapper reads from a context (two requests of different tenants, say, carrying the wrapper's own context keys): an entry written under the first must read back the same under each of the others. CheckWrapper cannot guess a wrapper's context keys, so with fewer than two contexts it fails the test rather than check nothing.

func Holder added in v0.21.0

func Holder(t *testing.T, open func(t *testing.T) agent.Store)

Holder checks agent.Holder on a store that implements it, with the store's Redactor: that a hold is kept and listed, that placing a duplicate or a malformed hold is refused, that a store refuses to replace a record of a run a hold covers (a run named by it, or with Tree a sub-agent run below one), and that lifting the hold lets the erasure go ahead. Run calls it for a store that implements agent.Holder and agent.Redactor.

func Redactor added in v0.21.0

func Redactor(t *testing.T, open func(t *testing.T) agent.Store)

Redactor checks agent.Redactor on a store that implements it: that a redaction replaces one entry's bytes with a tombstone and nothing else (position, name and every other entry unchanged), and that it refuses, writing nothing, a run that is not over, a run with a live lease, a protected record, a tombstone that does not keep the bytes' leaf hash, an entry that is not the one the caller read, and an entry the run does not hold. Run calls it for a store that implements agent.Redactor.

func Run

func Run(t *testing.T, open func(t *testing.T) agent.Store)

Run runs the whole suite: the store requirements (A1 to A8), the Lister contract when the store implements agent.Lister (with RunFilter.LeaseLapsed over its leases, or over none without agent.Leaser, and Leaser.ReapLeases when it has both), the journal header checks, the Journal's shared in-flight steps and claims, and the record-fidelity suite over a Journal on the store.

Types

type Case

type Case struct {
	Name   string
	Record agent.Record
	Want   json.RawMessage
}

Case is one record the suite round-trips. Want, when set, is the Result the store must hand back: the record's canonical form, which is the tool's JSON with insignificant whitespace removed and every other byte kept.

func Cases

func Cases() []Case

Cases returns the records the suite round-trips, for stores that want to run further checks (such as comparing the bytes they persisted) on the same inputs.

Jump to

Keyboard shortcuts

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