mock

package
v0.0.1 Latest Latest
Warning

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

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

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

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