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

storetest

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 15 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 CheckDurableWrapper

func CheckDurableWrapper(t testing.TB, wrap func(agent.Durable) agent.Durable, ctxs ...context.Context)

CheckDurableWrapper checks a Durable wrapper (one the engine drives through its Do and History, such as audit.AuditedStore) against the same rules (see agent.Durable): its mapping of run IDs and names to recorded steps does not depend on the context, and it implements Unwrap() Durable only if it passes run IDs and names through unchanged. A wrapper that rewrites keys (a tenant prefix) and unwraps would share with other wrappers over the same store what the process keeps per run (remembered claims, kept spend), under the rewritten run's name; it must not unwrap. wrap wraps the Durable it is given; CheckDurableWrapper wraps a MemStore. ctxs are as for CheckWrapper: at least two contexts that differ in the values the wrapper reads.

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

func RunDurable

func RunDurable(t *testing.T, open func(t *testing.T) agent.Durable)

RunDurable runs the record-fidelity suite against a Durable (a Journal, or a store's transitional Do and History). open returns a handle on the journal under test; run IDs are unique per call, so the suite can run repeatedly against a persistent backend. Run includes it, over a Journal on the store under test.

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