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 ¶
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.
Click to show internal directories.
Click to hide internal directories.