impl

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: BSD-3-Clause Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashOnlyParamKey

func HashOnlyParamKey[T any](t moq.T, val T, name string, n int, iType moq.ParamIndexing, anyParams uint64) hash.Hash

HashOnlyParamKey returns a parameter's hash if anyParams determines the parameter is not ignored (a zero value is returned if the parameter is ignored). If iType indicates that a parameter should be indexed by value, a fatal test failure is recorded and the test failed. Mocks should call HashOnlyParamKey for parameters that are incompatible with a parameter key.

func ParamKey

func ParamKey[T comparable](val T, n int, iType moq.ParamIndexing, anyParams uint64) (T, hash.Hash)

ParamKey returns a parameter's values if anyParams determines the parameter is not ignored (zero values are returned if the parameter is ignored). iType is used to determine if a parameter is indexed by value or by hash. Parameters indexed by value have a value returned and a zero-value hash. Parameters indexed by hash have a hash value returned and a zero-value value.

Types

type Adaptor

type Adaptor[P any, K comparable] interface {
	PrettyParams(params P) string
	ParamsKey(params P, anyParams uint64) K
}

Adaptor defines the interface all mocks need to implement for this implementation to interact properly

type DoFn

type DoFn[P any] func(params P)

DoFn defines the type of function needed when calling AndDo

type DoReturnFn

type DoReturnFn[P any, R any] func(params P) (results *R)

DoReturnFn defines the type of function needed when calling DoReturnResults

type Moq

type Moq[A Adaptor[P, K], P any, K comparable, R any] struct {
	Scene  *moq.Scene
	Config moq.Config

	Adaptor         A
	ResultsByParams []ResultsByParams[P, K, R]
}

Moq holds the state of a mocked function

func NewMoq

func NewMoq[A Adaptor[P, K], P any, K comparable, R any](
	scene *moq.Scene,
	adaptor A,
	config *moq.Config,
) *Moq[A, P, K, R]

NewMoq creates a new mock

func (*Moq[A, P, K, R]) AssertExpectationsMet

func (m *Moq[A, P, K, R]) AssertExpectationsMet()

AssertExpectationsMet asserts that all expectations have been met

func (*Moq[A, P, K, R]) Function

func (m *Moq[A, P, K, R]) Function(params P) *R

Function implements a function call

func (*Moq[A, P, K, R]) OnCall

func (m *Moq[A, P, K, R]) OnCall(params P) *Recorder[A, P, K, R]

OnCall prepares a mock to record a new expected function call

func (*Moq[A, P, K, R]) Reset

func (m *Moq[A, P, K, R]) Reset()

Reset resets the state of the mock

type Recorder

type Recorder[A Adaptor[P, K], P any, K comparable, R any] struct {
	Scene *moq.Scene
	Moq   *Moq[A, P, K, R]

	Adaptor   A
	Params    P
	AnyParams uint64
	Sequence  bool
	Results   *Results[P, R]
}

Recorder routes recorded function calls to the mock

func (*Recorder[A, P, K, R]) AndDo

func (r *Recorder[A, P, K, R]) AndDo(fn DoFn[P], exported bool) bool

AndDo records a "do function" that is called in addition to returning the results specified by ReturnResults

func (*Recorder[A, P, K, R]) AnyParam

func (r *Recorder[A, P, K, R]) AnyParam(n int)

AnyParam records that a parameter should not be used when recording an expectation and that the parameter should also not be used to find results

func (*Recorder[A, P, K, R]) DoReturnResults

func (r *Recorder[A, P, K, R]) DoReturnResults(fn DoReturnFn[P, R])

DoReturnResults records a "do return function" that is called to determine the results to return. Each call to ReturnResults or DoReturnResults indicates an additional mock call.

func (*Recorder[A, P, K, R]) IsAnyPermitted

func (r *Recorder[A, P, K, R]) IsAnyPermitted(exported bool) bool

IsAnyPermitted checks if "any params" can currently be set by checking the state of the recorder. It should be called by a mock before setting an any param.

func (*Recorder[A, P, K, R]) Repeat

func (r *Recorder[A, P, K, R]) Repeat(repeaters []moq.Repeater, exported bool) bool

Repeat records how many repeated calls are expected

func (*Recorder[A, P, K, R]) ReturnResults

func (r *Recorder[A, P, K, R]) ReturnResults(results R)

ReturnResults records the results to be returned by a mock

func (*Recorder[A, P, K, R]) Seq

func (r *Recorder[A, P, K, R]) Seq(seq bool, fnName string, exported bool) bool

Seq is called by Seq and NoSeq in a mock to specify whether a sequence value should be reserved and then checked by the mock

type Results

type Results[P any, R any] struct {
	Params  P
	Results []struct {
		Values     *R
		Sequence   uint32
		DoFn       DoFn[P]
		DoReturnFn DoReturnFn[P, R]
	}
	Index  uint32
	Repeat *moq.RepeatVal
}

Results holds the inner results which determine how a coll is validated and responded to

type ResultsByParams

type ResultsByParams[P any, K comparable, R any] struct {
	AnyCount  int
	AnyParams uint64
	Results   map[K]*Results[P, R]
}

ResultsByParams contains the results for a given set of parameters

Jump to

Keyboard shortcuts

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