mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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] or cache.BatchCache[T] — cache's own tests do not depend on this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchCacheMock

type BatchCacheMock[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)

	// 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) error

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

BatchCacheMock is a mock implementation of cache.BatchCache.

func TestSomethingThatUsesBatchCache(t *testing.T) {

	// make and configure a mocked cache.BatchCache
	mockedBatchCache := &BatchCacheMock{
		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")
		},
		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) error {
			panic("mock out the Set method")
		},
		SetManyFunc: func(ctx context.Context, items map[string]*T) error {
			panic("mock out the SetMany method")
		},
	}

	// use mockedBatchCache in code that requires cache.BatchCache
	// and then make assertions.

}

func (*BatchCacheMock[T]) Delete

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

Delete calls DeleteFunc.

func (*BatchCacheMock[T]) DeleteCalls

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

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

len(mockedBatchCache.DeleteCalls())

func (*BatchCacheMock[T]) Get

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

Get calls GetFunc.

func (*BatchCacheMock[T]) GetCalls

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

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

len(mockedBatchCache.GetCalls())

func (*BatchCacheMock[T]) GetMany

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

GetMany calls GetManyFunc.

func (*BatchCacheMock[T]) GetManyCalls

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

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

len(mockedBatchCache.GetManyCalls())

func (*BatchCacheMock[T]) Ping

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

Ping calls PingFunc.

func (*BatchCacheMock[T]) PingCalls

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

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

len(mockedBatchCache.PingCalls())

func (*BatchCacheMock[T]) Set

func (mock *BatchCacheMock[T]) Set(ctx context.Context, key string, value *T) error

Set calls SetFunc.

func (*BatchCacheMock[T]) SetCalls

func (mock *BatchCacheMock[T]) SetCalls() []struct {
	Ctx   context.Context
	Key   string
	Value *T
}

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

len(mockedBatchCache.SetCalls())

func (*BatchCacheMock[T]) SetMany

func (mock *BatchCacheMock[T]) SetMany(ctx context.Context, items map[string]*T) error

SetMany calls SetManyFunc.

func (*BatchCacheMock[T]) SetManyCalls

func (mock *BatchCacheMock[T]) SetManyCalls() []struct {
	Ctx   context.Context
	Items map[string]*T
}

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

len(mockedBatchCache.SetManyCalls())

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]) Delete

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

Delete calls DeleteFunc.

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]) 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]) 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) error

Set calls SetFunc.

func (*CacheMock[T]) SetCalls

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

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

len(mockedCache.SetCalls())

Jump to

Keyboard shortcuts

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