moq

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Overview

Package moq is used by test code to interact with Moqueries mocks

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FnString added in v0.2.0

func FnString(fn interface{}) string

FnString returns a string representing a function for use in error reporting

Types

type AnyTimer

type AnyTimer struct{}

AnyTimer holds an any times value

func AnyTimes

func AnyTimes() AnyTimer

AnyTimes returns an any times value

type Config

type Config struct {
	Expectation ExpectationMode
	Sequence    SequenceMode
}

Config is passed to a moq to provide configuration for the moq

type ExpectationMode

type ExpectationMode int

ExpectationMode determines the behavior of a moq when a method is invoked with no matching expectations

const (
	// Strict mode causes a moq to validate each method invocation
	Strict ExpectationMode = iota
	// Nice mode will return zero values for any unexpected invocation
	Nice
)

type MaxTimer

type MaxTimer int

MaxTimer holds a maximum times value

func MaxTimes

func MaxTimes(times int) MaxTimer

MaxTimes returns a maximum times value

type MinTimer

type MinTimer int

MinTimer holds a minimum times value

func MinTimes

func MinTimes(times int) MinTimer

MinTimes returns a minimum times value

type Moq

type Moq interface {
	Reset()
	AssertExpectationsMet()
}

Moq is implemented by all moqs so that they can integrate with a scene

type OptionalTimer

type OptionalTimer struct{}

OptionalTimer holds an optional value

func Optional

func Optional() OptionalTimer

Optional is similar to calling MinTimes(0) but doesn't change the max

type ParamIndexing

type ParamIndexing int

ParamIndexing values determine how parameters are indexed in a moq

const (
	// ParamIndexByValue indicates that a specific parameter of a specific
	// function will be indexed by it value alone. The parameter value will be
	// copied into a parameter key so simple equality will determine if an
	// expectation matches an actual call. The exact same instance must be
	// supplied to both the expectation call and the actual call.
	ParamIndexByValue ParamIndexing = iota
	// ParamIndexByHash indicates that a specific parameter of a specific
	// function will be indexed by a deep hash value. A deep hash library is
	// used to uniquely identify the parameter's value which includes the
	// values of any parameter subtypes. The exact same instance will only
	// match an expectation to an actual call if the internal state of the
	// instance hasn't changed.
	ParamIndexByHash
)

type RepeatVal

type RepeatVal struct {
	// MinTimes and MaxTimes record the minimum and maximum number of times a
	// call must be made for a test to pass
	MinTimes, MaxTimes int
	// AnyTimes indicates that a call can be made any number of times
	AnyTimes bool
	// ResultCount is used by a moq to size the results slice large enough to
	// hold all the expected results
	ResultCount int
	// ExplicitAny indicates that AnyTimes is true from an explicit use of
	// moq.AnyTimes
	ExplicitAny bool
	// Incremented indicates that Increment has been called as required before
	// calling Repeat
	Incremented bool
}

RepeatVal is a compilation of multiple repeaters for use in a moq

func (*RepeatVal) Increment

func (v *RepeatVal) Increment(t T)

Increment must be called by a moq each time results are expected and must be called prior to the optional call to Repeat

func (*RepeatVal) Repeat

func (v *RepeatVal) Repeat(t T, repeaters []Repeater)

Repeat compiles multiple repeaters into a value that can be used by a moq. If Repeat detects any rule violations (e.g.: conflicting repeaters), t.Fatalf is called to stop the test.

type Repeater

type Repeater interface {
	// contains filtered or unexported methods
}

Repeater is implemented by all repeaters

type Scene

type Scene struct {
	T T
	// contains filtered or unexported fields
}

Scene stores a collection of moqs so that they can work together

func NewScene

func NewScene(t T) *Scene

NewScene creates a new empty scene with no moqs

func (*Scene) AddMoq

func (s *Scene) AddMoq(m Moq)

AddMoq adds a moq to a scene

func (*Scene) AssertExpectationsMet

func (s *Scene) AssertExpectationsMet()

AssertExpectationsMet asserts that all expectations for all moqs in the scene are met

func (*Scene) NextMockSequence

func (s *Scene) NextMockSequence() uint32

NextMockSequence returns the next sequence value when a call is being made to a mock

func (*Scene) NextRecorderSequence

func (s *Scene) NextRecorderSequence() uint32

NextRecorderSequence returns the next sequence value for a recorder when recording expectations

func (*Scene) Reset

func (s *Scene) Reset()

Reset resets the state of all moqs in the scene so that they can be used in another test

type SequenceMode

type SequenceMode int

SequenceMode is used in conjunction with the generated seq and noSeq methods when checking call sequences

const (
	// SeqDefaultOff indicates that call sequences will not be reserved for any
	// calls but individual calls can turn on sequences
	SeqDefaultOff SequenceMode = iota
	// SeqDefaultOn indicates that call sequences will be reserved for all
	// calls but individual calls can turn off sequences
	SeqDefaultOn
)

type T

type T interface {
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Helper()
}

T is the interface defining standard library *testing.T methods used by Moqueries

type Timer

type Timer int

Timer holds a times value (min and max set to same value)

func Times

func Times(times int) Timer

Times returns a times value (min and max set to same value)

Jump to

Keyboard shortcuts

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