# store/storetest

> Package storetest is the conformance kit for store.LogStore implementations.

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/store/storetest (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
import "github.com/barevoidco/zelk/core/store/storetest"
```

Package storetest is the conformance kit for [store.LogStore](/reference/go/store/#logstore) implementations. Every store, zelk's own and any a host writes, runs [Run](/reference/go/store-storetest/#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").


## Run

```go
func Run(t *testing.T, f Factory)
```

Run checks that the stores made by f behave as [store.LogStore](/reference/go/store/#logstore) and the rules in docs/design/durability.md ("Leases and stores") require.


## RunInbox

```go
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

```go
type Factory func(t *testing.T) Subject
```

Factory sets up one store's empty backing state for a case.


## Subject

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