store/storetest
import "github.com/barevoidco/zelk/core/store/storetest"Package storetest is the conformance kit for store.LogStore implementations. Every store, zelk’s own and any a host writes, runs Run in its tests:
func TestConformance(t *testing.T) { storetest.Run(t, func(t *testing.T) storetest.Subject { dir := t.TempDir() return storetest.Subject{Open: func(t *testing.T) store.LogStore { return mystore.Open(dir) }} })}The kit opens several stores over one backing state, as separate processes or a restart would, so it checks what must hold between them: durable fences, handoff to a new holder while the old store is open, and adoption (docs/design/durability.md, “Leases and stores”).
func Run(t *testing.T, f Factory)Run checks that the stores made by f behave as store.LogStore and the rules in docs/design/durability.md (“Leases and stores”) require.
RunInbox
Section titled “RunInbox”func RunInbox(t *testing.T, f Factory)RunInbox checks ordering, bounded folding, immutable reads, trim, concurrent writers, reopening, removal and crash durability of a store’s Inbox capability.
Factory
Section titled “Factory”type Factory func(t *testing.T) SubjectFactory sets up one store’s empty backing state for a case.
Subject
Section titled “Subject”type Subject struct { // Open opens a store over the state. Every store opened must share // it: for an in-memory store, the same store; for one kept in files // or a database, a new store over the same files or tables, as // another process, or the same process after a restart, would open. // The stores it opens are closed by the factory's own cleanup. Open func(t *testing.T) store.LogStore // Crash, if set, simulates a power loss: everything the stores // acknowledged survives and anything else may not, and the stores // opened before it are abandoned. Stores whose durability can be // modelled set it (the file store on a fake file system), and the kit // then checks what must survive. It may be nil. Crash func(t *testing.T)}Subject is one case’s backing state.