cachetest

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cachetest provides a mock implementation of gas.CacheProvider for use in tests. The mock records all calls and allows configuring per-method behavior via function fields.

mock := &cachetest.MockCache{}
mock.GetFn = func(ctx context.Context, key string) ([]byte, error) {
    return []byte("value"), nil
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Method string
	Args   []any
}

Call records a single method invocation on the mock.

type MockCache

type MockCache struct {
	GetFn         func(ctx context.Context, key string) ([]byte, error)
	SetFn         func(ctx context.Context, key string, value []byte, ttl time.Duration) error
	DeleteFn      func(ctx context.Context, key string) error
	ExistsFn      func(ctx context.Context, key string) (bool, error)
	CheckHealthFn func(ctx context.Context) error
	CheckReadyFn  func(ctx context.Context) error
	Calls         []Call
	// contains filtered or unexported fields
}

MockCache is a configurable mock of gas.CacheProvider. Each method delegates to its corresponding Fn field if set, otherwise returns the zero value. All calls are recorded in the Calls slice for assertions.

func (*MockCache) CallCount

func (m *MockCache) CallCount(method string) int

CallCount returns the number of times the given method was called.

func (*MockCache) CheckHealth

func (m *MockCache) CheckHealth(ctx context.Context) error

CheckHealth records the call and delegates to CheckHealthFn if set.

func (*MockCache) CheckReady

func (m *MockCache) CheckReady(ctx context.Context) error

CheckReady records the call and delegates to CheckReadyFn if set.

func (*MockCache) Delete

func (m *MockCache) Delete(ctx context.Context, key string) error

Delete records the call and delegates to DeleteFn if set.

func (*MockCache) Exists

func (m *MockCache) Exists(ctx context.Context, key string) (bool, error)

Exists records the call and delegates to ExistsFn if set.

func (*MockCache) Get

func (m *MockCache) Get(ctx context.Context, key string) ([]byte, error)

Get records the call and delegates to GetFn if set.

func (*MockCache) Reset

func (m *MockCache) Reset()

Reset clears all recorded calls.

func (*MockCache) Set

func (m *MockCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set records the call and delegates to SetFn if set.

Jump to

Keyboard shortcuts

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