storetest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storetest is the one conformance suite of store.Store. Every adapter (mongostore, sqlitestore) runs it from its own tests:

func TestConformance(t *testing.T) {
	storetest.Run(t, func(t *testing.T, cascades ...store.Cascade) store.Store { ... })
}

The suite pins the semantics of Family Hub's MongoDB store (docs/PLAN.md §4.2), so the adapters are interchangeable:

  • times are kept at least to the millisecond and come back in UTC (the suite truncates to the millisecond);
  • a write to one entity that does not exist returns core.ErrNotFound, except deleting a session and the bulk operations (DeleteByPerson, RevokeKind, RevokeGrantsByResource, RevokeFamily, Delete*Expired*), which are idempotent;
  • inserting an id or another unique key that exists returns core.ErrConflict, except the Put methods, which replace; a second active grant of the same (person, client, resource) is core.ErrConflict too;
  • Revoke* methods are idempotent: the first revocation time wins;
  • an expiry is reached when ExpiresAt <= now; a session is idle when LastSeenAt < now - idle;
  • lists are oldest first (by creation time, then id); the audit is newest first, by its store-assigned id, and a cursor that is not an audit id is an error; a limit <= 0 means 50 and a limit above 1000 means 1000;
  • AccountStore.Delete runs Cascade.DeletePerson for every person of the account, then Cascade.DeleteAccount; PersonStore.Delete runs Cascade.DeletePerson. Every Cascade runs inside the delete's transaction, and an error from one rolls the whole delete back;
  • Tx: commit, rollback on an error from fn, a Tx inside a Tx joins the outer one, and a write inside an open transaction is invisible to a reader outside it until the commit (a reader outside never waits for it).

Each test opens its own store, and the tests run in parallel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, open Open)

Run runs the whole suite against the stores open makes.

Types

type Call

type Call struct {
	Account core.AccountID
	Person  core.PersonID
}

Call is one call of a Cascade: Account is set for DeleteAccount, Person for DeletePerson.

type Open

type Open func(t *testing.T, cascades ...store.Cascade) store.Store

Open returns a new, empty store with cascades registered. It arranges (with t.Cleanup) for the store to be closed and its data removed when the test ends.

type Recorder

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

Recorder is a store.Cascade that records every call and runs an optional hook with the call's context, so a test can write through the store inside the delete's transaction or make the cascade fail.

func (*Recorder) Calls

func (r *Recorder) Calls() []Call

Calls returns the distinct calls so far, in the order of their first appearance. A store may run a transaction again after a transient error, so a call may happen more than once.

func (*Recorder) DeleteAccount

func (r *Recorder) DeleteAccount(ctx context.Context, a core.AccountID) error

DeleteAccount implements store.Cascade.

func (*Recorder) DeletePerson

func (r *Recorder) DeletePerson(ctx context.Context, p core.PersonID) error

DeletePerson implements store.Cascade.

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset forgets the recorded calls.

func (*Recorder) SetHook

func (r *Recorder) SetHook(fn func(ctx context.Context, c Call) error)

SetHook sets the function every later call runs (nil: none).

Jump to

Keyboard shortcuts

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