Documentation ¶
Overview ¶
Package moka provides a mocking framework for the Go programming language. Moka works very well with the Ginkgo testing framework, but can be easily used with any other testing framework, including the testing package from the standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterDoublesFailHandler ¶
func RegisterDoublesFailHandler(failHandler FailHandler)
RegisterDoublesFailHandler registers a function as the global fail handler used by newly instantiated Moka doubles.
func VerifyCalls ¶
func VerifyCalls(double Double)
VerifyCalls verifies that all expected interactions on the wrapper `Double` have actually happened.
Types ¶
type AllowanceTarget ¶
type AllowanceTarget struct {
// contains filtered or unexported fields
}
AllowanceTarget wraps a Double to enable the configuration of allowed interactions on it.
func AllowDouble ¶
func AllowDouble(double Double) AllowanceTarget
AllowDouble wraps a Double in an `AllowanceTarget`.
func (AllowanceTarget) To ¶
func (t AllowanceTarget) To(interactionBuilder InteractionBuilder)
To configures the interaction built by the provided `InteractionBuilder` on the wrapped `Double`.
type ArgsInteractionBuilder ¶
type ArgsInteractionBuilder struct {
// contains filtered or unexported fields
}
ArgsInteractionBuilder allows to build interactions that are defined by a method name, a list of arguments and a list of return values
func (ArgsInteractionBuilder) AndReturn ¶
func (b ArgsInteractionBuilder) AndReturn(returnValues ...interface{}) ArgsInteractionBuilder
AndReturn allows to specify the return value of the interaction.
type BodyInteractionBuilder ¶
type BodyInteractionBuilder struct {
// contains filtered or unexported fields
}
BodyInteractionBuilder allows to build interactions that are defined by a method name and a custom body
type Double ¶
type Double interface { Call(methodName string, args ...interface{}) ([]interface{}, error) // contains filtered or unexported methods }
Double is the interface implemented by all Moka double types.
type ExpectationTarget ¶
type ExpectationTarget struct {
// contains filtered or unexported fields
}
ExpectationTarget wraps a Double to enable the configuration of expected interactions on it.
func ExpectDouble ¶
func ExpectDouble(double Double) ExpectationTarget
ExpectDouble wraps a Double in an `ExpectationTarget`.
func (ExpectationTarget) To ¶
func (t ExpectationTarget) To(interactionBuilder InteractionBuilder)
To configures the interaction built by the provided `InteractionBuilder` on the wrapped `Double`.
type FailHandler ¶
FailHandler is the type required for Moka fail handler functions. It matches the type of the Ginkgo `Fail` function.
type InteractionBuilder ¶
type InteractionBuilder interface {
// contains filtered or unexported methods
}
InteractionBuilder provides a fluid interface to build interactions to configure on a `Double`
type MethodInteractionBuilder ¶
type MethodInteractionBuilder struct {
// contains filtered or unexported fields
}
MethodInteractionBuilder allows to build interactions that are specific to a method. It turns into more specific builders through the fluid interface methods.
func ReceiveCallTo ¶
func ReceiveCallTo(methodName string) MethodInteractionBuilder
ReceiveCallTo allows to specify the method name of the interaction.
func (MethodInteractionBuilder) AndDo ¶
func (b MethodInteractionBuilder) AndDo(body interface{}) BodyInteractionBuilder
AndDo allows to specify a custom body to be executed by the interaction.
func (MethodInteractionBuilder) AndReturn ¶
func (b MethodInteractionBuilder) AndReturn(returnValues ...interface{}) ArgsInteractionBuilder
AndReturn allows to specify the return value of the interaction.
func (MethodInteractionBuilder) With ¶
func (b MethodInteractionBuilder) With(args ...interface{}) ArgsInteractionBuilder
With allows to specify the expected arguments of the interaction.
type StrictDouble ¶
type StrictDouble struct {
// contains filtered or unexported fields
}
StrictDouble is a strict implementation of the Double interface. Any invocation of the `Call` method that won't match any of the configured interactions will trigger a test failure and return an error.
func NewStrictDouble ¶
func NewStrictDouble() *StrictDouble
NewStrictDouble instantiates a new `StrictDouble`, using the global fail handler and no validation on the configured interactions.
func NewStrictDoubleWithTypeOf ¶
func NewStrictDoubleWithTypeOf(value interface{}) *StrictDouble
NewStrictDoubleWithTypeOf instantiates a new `StrictDouble`, using the global fail handler and validating that any configured interaction matches the specified type.
func (*StrictDouble) Call ¶
func (d *StrictDouble) Call(methodName string, args ...interface{}) ([]interface{}, error)
Call performs a method call on the double. If a matching interaction is found, its return values will be returned. If no configured interaction matches, an error will be returned.