storetest

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 13 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(...) })
}

Index

Constants

View Source
const T0 int64 = 1767605400000

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

Variables

This section is empty.

Functions

func FinishOnce

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.

func NewRun

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.

func NewRunPlain

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

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

func ReplayFixture

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.

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

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

Capture is a channel that keeps the alerts it is sent.

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

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

Clock is a settable clock for a client.

func NewClock

func NewClock(start int64) *Clock

NewClock is a clock at start.

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

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

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

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

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

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

func NewProcess

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.

type Shared

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.

Jump to

Keyboard shortcuts

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