Documentation
¶
Index ¶
- func HashOnlyParamKey[T any](t moq.T, val T, name string, n int, iType moq.ParamIndexing, anyParams uint64) hash.Hash
- func ParamKey[T comparable](val T, n int, iType moq.ParamIndexing, anyParams uint64) (T, hash.Hash)
- type Adaptor
- type DoFn
- type DoReturnFn
- type Moq
- type Recorder
- func (r *Recorder[A, P, K, R]) AndDo(fn DoFn[P], exported bool) bool
- func (r *Recorder[A, P, K, R]) AnyParam(n int)
- func (r *Recorder[A, P, K, R]) DoReturnResults(fn DoReturnFn[P, R])
- func (r *Recorder[A, P, K, R]) IsAnyPermitted(exported bool) bool
- func (r *Recorder[A, P, K, R]) Repeat(repeaters []moq.Repeater, exported bool) bool
- func (r *Recorder[A, P, K, R]) ReturnResults(results R)
- func (r *Recorder[A, P, K, R]) Seq(seq bool, fnName string, exported bool) bool
- type Results
- type ResultsByParams
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 ¶
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
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 ¶
AndDo records a "do function" that is called in addition to returning the results specified by ReturnResults
func (*Recorder[A, P, K, R]) AnyParam ¶
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 ¶
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]) ReturnResults ¶
func (r *Recorder[A, P, K, R]) ReturnResults(results R)
ReturnResults records the results to be returned by a 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