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 ¶
- type CacheMock
- func (mock *CacheMock[T]) Close() error
- func (mock *CacheMock[T]) CloseCalls() []struct{}
- func (mock *CacheMock[T]) Delete(ctx context.Context, key string) error
- func (mock *CacheMock[T]) DeleteByPrefix(ctx context.Context, prefix string) error
- func (mock *CacheMock[T]) DeleteByPrefixCalls() []struct{ ... }
- func (mock *CacheMock[T]) DeleteCalls() []struct{ ... }
- func (mock *CacheMock[T]) DeleteMany(ctx context.Context, keys []string) error
- func (mock *CacheMock[T]) DeleteManyCalls() []struct{ ... }
- func (mock *CacheMock[T]) Flush(ctx context.Context) error
- func (mock *CacheMock[T]) FlushCalls() []struct{ ... }
- func (mock *CacheMock[T]) Get(ctx context.Context, key string) (*T, error)
- func (mock *CacheMock[T]) GetCalls() []struct{ ... }
- func (mock *CacheMock[T]) GetMany(ctx context.Context, keys []string) (map[string]*T, error)
- func (mock *CacheMock[T]) GetManyCalls() []struct{ ... }
- func (mock *CacheMock[T]) Ping(ctx context.Context) error
- func (mock *CacheMock[T]) PingCalls() []struct{ ... }
- func (mock *CacheMock[T]) Set(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error
- func (mock *CacheMock[T]) SetCalls() []struct{ ... }
- func (mock *CacheMock[T]) SetIfPresent(ctx context.Context, key string, value *T, opts ...cache.WriteOption) error
- func (mock *CacheMock[T]) SetIfPresentCalls() []struct{ ... }
- func (mock *CacheMock[T]) SetMany(ctx context.Context, items map[string]*T, opts ...cache.WriteOption) error
- func (mock *CacheMock[T]) SetManyCalls() []struct{ ... }
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]) 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]) DeleteByPrefix ¶
DeleteByPrefix calls DeleteByPrefixFunc.
func (*CacheMock[T]) DeleteByPrefixCalls ¶
DeleteByPrefixCalls gets all the calls that were made to DeleteByPrefix. Check the length with:
len(mockedCache.DeleteByPrefixCalls())
func (*CacheMock[T]) DeleteCalls ¶
DeleteCalls gets all the calls that were made to Delete. Check the length with:
len(mockedCache.DeleteCalls())
func (*CacheMock[T]) DeleteMany ¶
DeleteMany calls DeleteManyFunc.
func (*CacheMock[T]) DeleteManyCalls ¶
DeleteManyCalls gets all the calls that were made to DeleteMany. Check the length with:
len(mockedCache.DeleteManyCalls())
func (*CacheMock[T]) FlushCalls ¶
FlushCalls gets all the calls that were made to Flush. Check the length with:
len(mockedCache.FlushCalls())
func (*CacheMock[T]) GetCalls ¶
GetCalls gets all the calls that were made to Get. Check the length with:
len(mockedCache.GetCalls())
func (*CacheMock[T]) GetManyCalls ¶
GetManyCalls gets all the calls that were made to GetMany. Check the length with:
len(mockedCache.GetManyCalls())
func (*CacheMock[T]) PingCalls ¶
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())