storetest

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package storetest is the test every CronWatch store passes: the memory store, and the sqlstore package on SQLite, Postgres, and MySQL. It is the SDK's store-conformance.ts, and a replay of the store cases in the repository's conformance/store.json. Run it against a store of your own:

func TestMyStore(t *testing.T) {
	storetest.Run(t, func(t *testing.T) cronwatch.Store { return mystore.New(...) })
}

Run is the one name here the 1.x releases promise. The other exported names are the module's own test kit (its fixture replays, clocks, and captures), deprecated, and go in 1.0.

Index

Constants

View Source
const T0 int64 = 1767605400000

T0 is Monday 2026-01-05 09:30:00Z, the SDK tests' clock start.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

Variables

This section is empty.

Functions

func FinishOnce deprecated

func FinishOnce(t *testing.T, shared func(t *testing.T) Shared)

FinishOnce is finish-once.test.ts's tests over several stores sharing one database: however many processes finish a run, it is recorded and judged once. shared makes a fresh database each time it is called.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func NewRun deprecated

func NewRun(id, job string, status cronwatch.RunStatus, startedAt int64) cronwatch.Run

NewRun is a run as the contract test writes them: finished ten milliseconds after it started unless it is running, with one metric.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func NewRunPlain deprecated

func NewRunPlain(id, job string, status cronwatch.RunStatus, startedAt int64) cronwatch.Run

NewRunPlain is the fixture script's run: as NewRun, with no metrics.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func ReplayFixture deprecated

func ReplayFixture(t *testing.T, path string, newStore func(t *testing.T) cronwatch.Store)

ReplayFixture replays the store cases of conformance/store.json (at path) against stores from newStore, which must each be empty: prune scripts, CompareAndSetState steps, and UpdateRunIf steps, each read back and compared with what the SDK's memory store answered.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func ReplayForeignVersions deprecated added in v0.8.0

func ReplayForeignVersions(t *testing.T, path string, store cronwatch.Store, writeRaw func(text string) error)

ReplayForeignVersions replays the foreignVersion cases of conformance/store.json (at path) against store, which must implement cronwatch.StateComparer: a state row another process wrote, its version in any shape (1.5, "x", -1, 2.0, 2^53), counts as the SDK's stateVersion() reads it, a whole number from 0 to 2^53 - 1 or else 0. So a write expecting any other version is refused, and one expecting it goes through, where a brittle cast would fail every write of the job for good. writeRaw stores a state row for job "v" holding the JSON text given as it is, as a store's own writes never would; the replay deletes job "v" before each case.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func Run

func Run(t *testing.T, newStore func(t *testing.T) cronwatch.Store)

Run is the contract test: store-conformance.ts, step for step. make is called once and must return an empty store (newStore).

Types

type Capture deprecated

type Capture struct {
	Alerts []cronwatch.Alert
	// contains filtered or unexported fields
}

Capture is a channel that keeps the alerts it is sent. Read them with List (or Types), which take its lock: a client sends from goroutines of its own, so reading Alerts directly is safe only once every send has returned.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func (*Capture) List added in v0.7.0

func (c *Capture) List() []cronwatch.Alert

List is a copy of the kept alerts, in order.

func (*Capture) Name

func (c *Capture) Name() string

Name is "capture".

func (*Capture) Send

Send keeps the alert.

func (*Capture) Types

func (c *Capture) Types() []string

Types are the kept alerts' types, in order.

type Clock deprecated

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

Clock is a settable clock for a client.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func NewClock deprecated

func NewClock(start int64) *Clock

NewClock is a clock at start.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func (*Clock) Advance

func (c *Clock) Advance(ms int64) int64

Advance moves the clock on by ms and answers the new time.

func (*Clock) Now

func (c *Clock) Now() int64

Now is the time.

func (*Clock) Set

func (c *Clock) Set(t int64)

Set moves the clock to t.

type Errors deprecated

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

Errors keeps what a client reports, as "where: message".

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func (*Errors) Add

func (e *Errors) Add(err error, where string)

Add keeps an error.

func (*Errors) List

func (e *Errors) List() []string

List is what was kept.

type Process deprecated

type Process struct {
	Client *cronwatch.Client
	Alerts *Capture
	Errors *Errors
}

Process is one client over a shared store, as one process would have.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

func NewProcess deprecated

func NewProcess(t *testing.T, store cronwatch.Store, now func() int64) *Process

NewProcess is a client over store, with a capture channel and an error list.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

type Shared deprecated

type Shared struct {
	Open func() cronwatch.Store
	// Done is called at the end, to close the stores and drop the data.
	Done func()
}

Shared opens stores over one database, as several processes would have them: each call to Open is another store on the same data.

Deprecated: only Run is promised; this is the module's own test kit, and goes in 1.0.

Jump to

Keyboard shortcuts

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