Documentation ¶
Index ¶
- type ArgumentMatcher
- type MatchAny
- type MatchType
- type Mock
- func (mock *Mock) Assert(t *testing.T) *mockAssertion
- func (mock *Mock) Called() bool
- func (mock *Mock) CalledOnce() bool
- func (mock *Mock) CalledTimes(n int) bool
- func (mock *Mock) CalledWith(args ...any) bool
- func (mock *Mock) CalledWithExactly(args ...any) bool
- func (mock *Mock) GetCalls() []MockCall
- func (mock *Mock) GetMethodResponse(methodName string, args ...any) (res methodResponse)
- func (mock *Mock) GetResponseAndRegister(methodName string, args ...any) (res methodResponse)
- func (mock *Mock) Method(name string) *method
- func (mock *Mock) RegisterMethodCall(methodName string, args ...any)
- func (mock *Mock) Reset()
- func (mock *Mock) SetMethodResponse(methodName string, response ...any)
- type MockCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgumentMatcher ¶ added in v1.3.0
An argument matcher it's an helper value that should be used when asserting a mock was called with a specific set of values.
Users can define their own argument matchers when they want to define what exactly should be matched when comparing the mock call argument with the expected argument.
type MatchAny ¶ added in v1.3.0
type MatchAny struct{}
MatchAny it's an argument matcher that matches anything. Use it on CalledWith or CalledWithExactly to match any argument.
type MatchType ¶ added in v1.3.0
type MatchType[T any] struct{}
MatchType it's an argument matcher that matches any value that's the same type as provided. Use it on CalledWith or CalledWithExactly to match an argument by type.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock represents a mock and its use information
func (*Mock) CalledOnce ¶
CalledOnce returns if a mock was called exactly once
func (*Mock) CalledTimes ¶
CalledTimes returns if a mock was called 'n' times
func (*Mock) CalledWith ¶
CalledWith returns if the mock was called at least once with the specified arguments
func (*Mock) CalledWithExactly ¶
CalledWithExactly returns if the mock was called at least once with exactly the specified arguments, with the same values and in the same order
func (*Mock) GetMethodResponse ¶
GetMethodResponse gets the specified response for a method
func (*Mock) GetResponseAndRegister ¶ added in v1.2.0
GetResponseAndRegister it's equivalent of calling RegisterMethodCall and GetMethodResponse subsequently.
It gets the specified response for a method, given the method name and the args, and also registers a method call given those args.
func (*Mock) RegisterMethodCall ¶
RegisterMethodCall registers a method call on a mock given the method name and the call arguments
func (*Mock) SetMethodResponse ¶
SetMethodResponse sets a response that the mock will return when calling the method specified in the methodName
Its imperative that the response values specified are of the same type and are in the same order as the method response specified in the method signature