cachemock

package
v11.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cachemock provides moq-generated mock implementations of interfaces in the cache package. The primary consumer is external tests that need to mock cache.Cache[T] — cache's own tests do not depend on this package. Batched operations are part of Cache itself, so CacheMock covers them too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheMock

type CacheMock[T any] struct {
	// CloseFunc mocks the Close method.
	CloseFunc func() error

	// DeleteFunc mocks the Delete method.
	DeleteFunc func(ctx context.Context, key string) error

	// DeleteByPrefixFunc mocks the DeleteByPrefix method.
	DeleteByPrefixFunc func(ctx context.Context, prefix string) error

	// DeleteManyFunc mocks the DeleteMany method.
	DeleteManyFunc func(ctx context.Context, keys []string) error

	// FlushFunc mocks the Flush method.
	FlushFunc func(ctx context.Context) error

	// GetFunc mocks the Get method.
	GetFunc func(ctx context.Context, key string) (*T, error)

	// GetManyFunc mocks the GetMany method.
	GetManyFunc func(ctx context.Context, keys []string) (map[string]*T, error)

	// PingFunc mocks the Ping method.
	PingFunc func(ctx context.Context) error

	// SetFunc mocks the Set method.
	SetFunc func(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error

	// SetIfPresentFunc mocks the SetIfPresent method.
	SetIfPresentFunc func(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error

	// SetManyFunc mocks the SetMany method.
	SetManyFunc func(ctx context.Context, items map[string]*T, opts ...cache.WriteOption) error
	// contains filtered or unexported fields
}

CacheMock is a mock implementation of cache.Cache.

func TestSomethingThatUsesCache(t *testing.T) {

	// make and configure a mocked cache.Cache
	mockedCache := &CacheMock{
		CloseFunc: func() error {
			panic("mock out the Close method")
		},
		DeleteFunc: func(ctx context.Context, key string) error {
			panic("mock out the Delete method")
		},
		DeleteByPrefixFunc: func(ctx context.Context, prefix string) error {
			panic("mock out the DeleteByPrefix method")
		},
		DeleteManyFunc: func(ctx context.Context, keys []string) error {
			panic("mock out the DeleteMany method")
		},
		FlushFunc: func(ctx context.Context) error {
			panic("mock out the Flush method")
		},
		GetFunc: func(ctx context.Context, key string) (*T, error) {
			panic("mock out the Get method")
		},
		GetManyFunc: func(ctx context.Context, keys []string) (map[string]*T, error) {
			panic("mock out the GetMany method")
		},
		PingFunc: func(ctx context.Context) error {
			panic("mock out the Ping method")
		},
		SetFunc: func(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error {
			panic("mock out the Set method")
		},
		SetIfPresentFunc: func(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error {
			panic("mock out the SetIfPresent method")
		},
		SetManyFunc: func(ctx context.Context, items map[string]*T, opts ...cache.WriteOption) error {
			panic("mock out the SetMany method")
		},
	}

	// use mockedCache in code that requires cache.Cache
	// and then make assertions.

}

func (*CacheMock[T]) Close

func (mock *CacheMock[T]) Close() error

Close calls CloseFunc.

func (*CacheMock[T]) CloseCalls

func (mock *CacheMock[T]) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedCache.CloseCalls())

func (*CacheMock[T]) Delete

func (mock *CacheMock[T]) Delete(ctx context.Context, key string) error

Delete calls DeleteFunc.

func (*CacheMock[T]) DeleteByPrefix

func (mock *CacheMock[T]) DeleteByPrefix(ctx context.Context, prefix string) error

DeleteByPrefix calls DeleteByPrefixFunc.

func (*CacheMock[T]) DeleteByPrefixCalls

func (mock *CacheMock[T]) DeleteByPrefixCalls() []struct {
	Ctx    context.Context
	Prefix string
}

DeleteByPrefixCalls gets all the calls that were made to DeleteByPrefix. Check the length with:

len(mockedCache.DeleteByPrefixCalls())

func (*CacheMock[T]) DeleteCalls

func (mock *CacheMock[T]) DeleteCalls() []struct {
	Ctx context.Context
	Key string
}

DeleteCalls gets all the calls that were made to Delete. Check the length with:

len(mockedCache.DeleteCalls())

func (*CacheMock[T]) DeleteMany

func (mock *CacheMock[T]) DeleteMany(ctx context.Context, keys []string) error

DeleteMany calls DeleteManyFunc.

func (*CacheMock[T]) DeleteManyCalls

func (mock *CacheMock[T]) DeleteManyCalls() []struct {
	Ctx  context.Context
	Keys []string
}

DeleteManyCalls gets all the calls that were made to DeleteMany. Check the length with:

len(mockedCache.DeleteManyCalls())

func (*CacheMock[T]) Flush

func (mock *CacheMock[T]) Flush(ctx context.Context) error

Flush calls FlushFunc.

func (*CacheMock[T]) FlushCalls

func (mock *CacheMock[T]) FlushCalls() []struct {
	Ctx context.Context
}

FlushCalls gets all the calls that were made to Flush. Check the length with:

len(mockedCache.FlushCalls())

func (*CacheMock[T]) Get

func (mock *CacheMock[T]) Get(ctx context.Context, key string) (*T, error)

Get calls GetFunc.

func (*CacheMock[T]) GetCalls

func (mock *CacheMock[T]) GetCalls() []struct {
	Ctx context.Context
	Key string
}

GetCalls gets all the calls that were made to Get. Check the length with:

len(mockedCache.GetCalls())

func (*CacheMock[T]) GetMany

func (mock *CacheMock[T]) GetMany(ctx context.Context, keys []string) (map[string]*T, error)

GetMany calls GetManyFunc.

func (*CacheMock[T]) GetManyCalls

func (mock *CacheMock[T]) GetManyCalls() []struct {
	Ctx  context.Context
	Keys []string
}

GetManyCalls gets all the calls that were made to GetMany. Check the length with:

len(mockedCache.GetManyCalls())

func (*CacheMock[T]) Ping

func (mock *CacheMock[T]) Ping(ctx context.Context) error

Ping calls PingFunc.

func (*CacheMock[T]) PingCalls

func (mock *CacheMock[T]) PingCalls() []struct {
	Ctx context.Context
}

PingCalls gets all the calls that were made to Ping. Check the length with:

len(mockedCache.PingCalls())

func (*CacheMock[T]) Set

func (mock *CacheMock[T]) Set(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error

Set calls SetFunc.

func (*CacheMock[T]) SetCalls

func (mock *CacheMock[T]) SetCalls() []struct {
	Ctx   context.Context
	Key   string
	Value *T
	Opts  []cache.WriteOption
}

SetCalls gets all the calls that were made to Set. Check the length with:

len(mockedCache.SetCalls())

func (*CacheMock[T]) SetIfPresent

func (mock *CacheMock[T]) SetIfPresent(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error

SetIfPresent calls SetIfPresentFunc.

func (*CacheMock[T]) SetIfPresentCalls

func (mock *CacheMock[T]) SetIfPresentCalls() []struct {
	Ctx   context.Context
	Key   string
	Value *T
	Opts  []cache.WriteOption
}

SetIfPresentCalls gets all the calls that were made to SetIfPresent. Check the length with:

len(mockedCache.SetIfPresentCalls())

func (*CacheMock[T]) SetMany

func (mock *CacheMock[T]) SetMany(ctx context.Context, items map[string]*T, opts ...cache.WriteOption) error

SetMany calls SetManyFunc.

func (*CacheMock[T]) SetManyCalls

func (mock *CacheMock[T]) SetManyCalls() []struct {
	Ctx   context.Context
	Items map[string]*T
	Opts  []cache.WriteOption
}

SetManyCalls gets all the calls that were made to SetMany. Check the length with:

len(mockedCache.SetManyCalls())

Jump to

Keyboard shortcuts

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