cachetest

package module
v0.1.5 Latest Latest
Warning

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

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

Documentation

Overview

Package cachetest provides reusable store contract tests for cache.Store implementations.

Driver modules can use this package from their own tests without importing root test helpers.

Example pattern (driver module test):

func TestRedisStoreContract(t *testing.T) {
	client := newTestRedisClient(t)
	store, err := rediscache.New(rediscache.Config{Client: client, Prefix: "test"})
	if err != nil {
		t.Fatalf("new redis store: %v", err)
	}

	// Namespace keys per test and tune TTL waits for backend semantics as needed.
	cachetest.RunStoreContract(t, store, cachetest.Options{
		CaseName: t.Name(),
		TTL:      time.Second,
		TTLWait:  1500 * time.Millisecond,
	})
}

Example factory/cleanup wrapper:

func runContractWithFactory(t *testing.T, mk func(t *testing.T) (cache.Store, func())) {
	t.Helper()
	store, cleanup := mk(t)
	t.Cleanup(cleanup)
	cachetest.RunStoreContract(t, store, cachetest.Options{CaseName: t.Name()})
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunStoreContract

func RunStoreContract(t *testing.T, store Store, opts Options)

RunStoreContract runs a backend-agnostic store contract suite.

Types

type Options

type Options struct {
	// CaseName is used to namespace keys. Defaults to t.Name().
	CaseName string
	// NullSemantics enables relaxed expectations for the null store.
	NullSemantics bool
	// SkipCloneCheck disables the "get returns a cloned value" assertion.
	SkipCloneCheck bool
	// TTL controls the expiry duration used in TTL tests.
	TTL time.Duration
	// TTLWait is how long the harness waits for expiry to occur.
	TTLWait time.Duration
	// SkipFlush disables the flush assertion for drivers where it is expensive or unavailable.
	SkipFlush bool
}

Options configures shared store contract checks.

type Store

type Store = cachecore.Store

Store is the minimal contract required by RunStoreContract.

Jump to

Keyboard shortcuts

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