Documentation ¶
Overview ¶
Package spies provides test spies for go test, in the vien of testify's mocks. Roughly speaking, define a spy like this:
type MySpy { *spies.Spy } func NewMySpy() *MySpy { return &MySpy{ NewSpy() } } func (my *MySpy) InterfaceMethod(with, some, args int) (ret string, err error) { res := my.Called(with, some, args) return res.String(0), res.Error(1) }
Use your spy in tests like:
my.MatchMethod("InterfaceMethod", spies.AnyArgs, "called", nil)
... which will return "called" with a nil error whenever InterfaceMethod is called. Several calls to Match and MatchMethod can be made in a row - the first match wins. Then you can check calls by calling my.Calls to my.CallsTo
Index ¶
- func Always(string, mock.Arguments) bool
- func AnyArgs(mock.Arguments) bool
- func CallCount(n int) func(mock.Arguments) bool
- func Once() func(mock.Arguments) bool
- type Call
- type PassedArger
- type Spy
- func (s *Spy) Any(method string, result ...interface{})
- func (s *Spy) Called(argList ...interface{}) results
- func (s *Spy) Calls() []Call
- func (s *Spy) CallsMatching(f func(name string, args mock.Arguments) bool) []Call
- func (s *Spy) CallsTo(name string) []Call
- func (s *Spy) Match(pred func(string, mock.Arguments) bool, result ...interface{})
- func (s *Spy) MatchMethod(method string, pred func(mock.Arguments) bool, result ...interface{})
- func (s *Spy) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PassedArger ¶
A PassedArger implements PassedArgs
type Spy ¶
A Spy is a type for use in testing - it's intended to be embedded in spy implementations.
func (*Spy) Called ¶
func (s *Spy) Called(argList ...interface{}) results
Called is used by embedders of Spy to indicate that the method is called.
func (*Spy) CallsMatching ¶
CallsMatching returns a list of calls for with f() returns true.
func (*Spy) MatchMethod ¶
MatchMethod records a predicate limited to a specific method name