
mocki
Generates mock implementations of interfaces using go generate. See the examples directory if you want to see what the generated code looks like.
Usage
Given an inteface and method like this:
package thinger
//go:generate mocki --interface-name=SimpleI --file-name=simple.go
type Thinger interface {
Foo(s string) string
}
func DoThingFoo(t Thinger, s string) string {
return t.Foo(s)
}
Running go generate will create a mock you can provide like this:
mt := MockThinger{
FooFn: func(s string) string {
// do anything
return "whatever"
}
}
output := DoThingFoo(mt, "something")
// output will be "whatever"
// mt.FooCalled() == true
// mt.FooCount() == 1
It will also generate a NOOP implementation you can use like this:
output := DoThingFoo(NOOPThinger(), "something")
// output will be nil (default values for return types)