storetest

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 13 Imported by: 0

README

storetest

import "github.com/kitsunium/sdk/framework/kit/storetest"

Package storetest is the conformance suite of kit's stores (ADR 0004): what a store does on every backend — in memory, in the data directory, on each database engine —, run by kit's tests on memory, files and kit's fake database, and by each engine module's tests on its engine. It is what keeps the test double honest: a product tested in memory sees what its database does.

func TestConformance(t *testing.T) {
	storetest.Run(t, storetest.BackendConfig{Name: "sqlite", Options: func(t *testing.T, app string) []kit.AppOption {
		return []kit.AppOption{kit.DataDir(t.TempDir()), kit.Database("database", sqlite.Engine())}
	}})
}

Each case declares a service of its own, with a name of its own, so the cases of one run can share one database: their tables never meet.

Index

Constants

const (
    // App is the name of the app every case runs: a database's URL is read
    // from STORETEST_<NAME>_URL.
    App string = "storetest"
)

CodeRolledBack is the code of the error a case returns from a transaction's function to roll it back — the suite's own, in the framework's range: layer 4, PP 4 this package (ADR 0147 §3). A store never returns it; the case that returned it expects kit.Transact to hand it back.

const CodeRolledBack errs.Code = 0x00_04_04_01 // 0.4.4.1

func Run

func Run(t *testing.T, b BackendConfig)

Run runs every case of the suite on b.

type BackendConfig

BackendConfig is where Run runs kit's stores: a name for the subtests and the options that place the stores there.

type BackendConfig struct {
    // Name names the backend in the subtests.
    Name string
    // Options place the stores of the app named app on the backend —
    // kit.InMemory(), kit.DataDir, a kit.Database whose URL the environment
    // holds —, once per case. A database is named "database": the suite
    // gives its calls a minute, as 32 writers of one entity queue on a
    // server's lock.
    Options func(t *testing.T, app string) []kit.AppOption
}

Generated by gomarkdoc

Documentation

Overview

Package storetest is the conformance suite of kit's stores (ADR 0004): what a store does on every backend — in memory, in the data directory, on each database engine —, run by kit's tests on memory, files and kit's fake database, and by each engine module's tests on its engine. It is what keeps the test double honest: a product tested in memory sees what its database does.

func TestConformance(t *testing.T) {
	storetest.Run(t, storetest.BackendConfig{Name: "sqlite", Options: func(t *testing.T, app string) []kit.AppOption {
		return []kit.AppOption{kit.DataDir(t.TempDir()), kit.Database("database", sqlite.Engine())}
	}})
}

Each case declares a service of its own, with a name of its own, so the cases of one run can share one database: their tables never meet.

Index

Constants

View Source
const (
	// App is the name of the app every case runs: a database's URL is read
	// from STORETEST_<NAME>_URL.
	App string = "storetest"
)
View Source
const CodeRolledBack errs.Code = 0x00_04_04_01 // 0.4.4.1

CodeRolledBack is the code of the error a case returns from a transaction's function to roll it back — the suite's own, in the framework's range: layer 4, PP 4 this package (ADR 0147 §3). A store never returns it; the case that returned it expects kit.Transact to hand it back.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, b BackendConfig)

Run runs every case of the suite on b.

Types

type BackendConfig

type BackendConfig struct {
	// Name names the backend in the subtests.
	Name string
	// Options place the stores of the app named app on the backend —
	// kit.InMemory(), kit.DataDir, a kit.Database whose URL the environment
	// holds —, once per case. A database is named "database": the suite
	// gives its calls a minute, as 32 writers of one entity queue on a
	// server's lock.
	Options func(t *testing.T, app string) []kit.AppOption
}

BackendConfig is where Run runs kit's stores: a name for the subtests and the options that place the stores there.

Jump to

Keyboard shortcuts

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