Documentation
¶
Overview ¶
Package cachefake provides an in-memory cache with deterministic operation assertions for tests.
Index ¶
- type Fake
- func (f *Fake) AssertCalled(t *testing.T, op Op, key string, times int)
- func (f *Fake) AssertNotCalled(t *testing.T, op Op, key string)
- func (f *Fake) AssertTotal(t *testing.T, op Op, times int)
- func (f *Fake) Cache() *cache.Cache
- func (f *Fake) Count(op Op, key string) int
- func (f *Fake) Reset()
- func (f *Fake) Total(op Op) int
- type Op
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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" )