Documentation
¶
Overview ¶
Package mock 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.
Index ¶
- type CacheMock
- func (mock *CacheMock[T]) Delete(ctx context.Context, key string) error
- func (mock *CacheMock[T]) DeleteCalls() []struct{ ... }
- func (mock *CacheMock[T]) Get(ctx context.Context, key string) (*T, error)
- func (mock *CacheMock[T]) GetCalls() []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) error
- func (mock *CacheMock[T]) SetCalls() []struct{ ... }
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheMock ¶
type CacheMock[T any] struct { // DeleteFunc mocks the Delete method. DeleteFunc func(ctx context.Context, key string) error // GetFunc mocks the Get method. GetFunc func(ctx context.Context, key 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) 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{
DeleteFunc: func(ctx context.Context, key string) error {
panic("mock out the Delete method")
},
GetFunc: func(ctx context.Context, key string) (*T, error) {
panic("mock out the Get method")
},
PingFunc: func(ctx context.Context) error {
panic("mock out the Ping method")
},
SetFunc: func(ctx context.Context, key string, value *T) error {
panic("mock out the Set method")
},
}
// use mockedCache in code that requires cache.Cache
// and then make assertions.
}
func (*CacheMock[T]) DeleteCalls ¶
DeleteCalls gets all the calls that were made to Delete. Check the length with:
len(mockedCache.DeleteCalls())
func (*CacheMock[T]) GetCalls ¶
GetCalls gets all the calls that were made to Get. Check the length with:
len(mockedCache.GetCalls())
func (*CacheMock[T]) PingCalls ¶
PingCalls gets all the calls that were made to Ping. Check the length with:
len(mockedCache.PingCalls())
Click to show internal directories.
Click to hide internal directories.