cachefake

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cachefake provides an in-memory cache with deterministic operation assertions for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

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

Fake exposes a deterministic in-memory store plus assertion helpers for tests. It wraps the memory store so no external services are needed.

func New

func New() *Fake

New creates a Fake using an in-memory store. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_ = c.SetString("settings:mode", "dark", 0)

func (*Fake) AssertCalled

func (f *Fake) AssertCalled(t *testing.T, op Op, key string, times int)

AssertCalled verifies key was touched by op the expected number of times. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_ = c.SetString("settings:mode", "dark", 0)
t := &testing.T{}
f.AssertCalled(t, cachefake.OpSet, "settings:mode", 1)

func (*Fake) AssertNotCalled

func (f *Fake) AssertNotCalled(t *testing.T, op Op, key string)

AssertNotCalled ensures key was never touched by op. @group Testing Helpers Example:

f := cachefake.New()
t := &testing.T{}
f.AssertNotCalled(t, cachefake.OpDelete, "settings:mode")

func (*Fake) AssertTotal

func (f *Fake) AssertTotal(t *testing.T, op Op, times int)

AssertTotal ensures the total call count for an op matches times. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_ = c.Delete("a")
_ = c.Delete("b")
t := &testing.T{}
f.AssertTotal(t, cachefake.OpDelete, 2)

func (*Fake) Cache

func (f *Fake) Cache() *cache.Cache

Cache returns the cache facade to inject into code under test. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_, _, _ = c.GetBytes("settings:mode")

func (*Fake) Count

func (f *Fake) Count(op Op, key string) int

Count returns calls for op+key. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_ = c.SetString("settings:mode", "dark", 0)
n := f.Count(cachefake.OpSet, "settings:mode")
_ = n

func (*Fake) Reset

func (f *Fake) Reset()

Reset clears recorded counts. @group Testing Helpers Example:

f := cachefake.New()
_ = f.Cache().SetString("settings:mode", "dark", 0)
f.Reset()

func (*Fake) Total

func (f *Fake) Total(op Op) int

Total returns total calls for an op across keys. @group Testing Helpers Example:

f := cachefake.New()
c := f.Cache()
_ = c.Delete("a")
_ = c.Delete("b")
n := f.Total(cachefake.OpDelete)
_ = n

type Op

type Op string

Op identifies a cache operation for assertions.

const (
	// OpGet identifies raw cache reads in fake assertions.
	OpGet Op = "get"
	// OpSet identifies unconditional cache writes in fake assertions.
	OpSet Op = "set"
	// OpAdd identifies conditional cache writes in fake assertions.
	OpAdd Op = "add"
	// OpInc identifies counter increments in fake assertions.
	OpInc Op = "inc"
	// OpDec identifies counter decrements in fake assertions.
	OpDec Op = "dec"
	// OpDelete identifies single-key removals in fake assertions.
	OpDelete Op = "delete"
	// OpDeleteMany identifies batch removals in fake assertions.
	OpDeleteMany Op = "delete_many"
	// OpFlush identifies namespace flushes in fake assertions.
	OpFlush Op = "flush"
)

Jump to

Keyboard shortcuts

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