cachetest

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cachetest is the contract suite every cache store passes.

A Store is an interface with six methods, and the difference between two implementations of it is meant to be invisible from the call site: the same application, wired to the in-process ArrayStore in a test and to the RESP store in production, must behave the same way. Nothing about the Go type system enforces that. This package does.

It is here and not in the store's own repository because there is one contract, not one per backend: a suite copied into each adapter drifts, and the copy that drifts is the one that stops noticing that a miss returns the backend's own not-found error instead of cache.ErrNotFound.

An adapter runs it in one test:

func TestStoreContract(t *testing.T) {
	cachetest.Run(t, func(t *testing.T) cache.Store {
		return newStoreAgainstAServerStartedForThisTest(t)
	})
}

The factory takes the *testing.T so an adapter can skip when its server is not available, and is called once per subtest so no subtest can be affected by what another one left behind.

It is named for net/http/httptest: a package whose name ends in "test" is a package that imports testing, and every consumer of this one is a test.

Package cachetest is the contract suite every Store passes.

It is what makes one behaviour test serve every backend: a Store built over memory, over the filesystem, over a table or over RESP is handed to the same suite, and a store that passes it can be dropped into a Repository without the Repository knowing which one it got.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

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

Run checks a Store against the contract Repository depends on.

func RunLocking

func RunLocking(t *testing.T, newStore func(*testing.T) cache.Locking)

RunLocking checks the lock half of a store: the two calls cache.Lock makes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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