The example program below will print "hellohello" instead of "helloworld" - this is because the MockFunction's ReturnValues are not reset between calls. That makes sense when using When and Return, but not when using Call.
package main
import (
"fmt"
mock "github.com/maraino/go-mock"
)
type myMock struct {
mock.Mock
}
func (m myMock) Fn() string {
r := m.Called()
return r.String(0)
}
func main() {
m := myMock{}
i := 0
vals := []string{"hello", "world"}
m.When("Fn").Call(func() string {
str := vals[i]
i += 1
return str
})
fmt.Print(m.Fn(), m.Fn())
}
The example program below will print "hellohello" instead of "helloworld" - this is because the MockFunction's ReturnValues are not reset between calls. That makes sense when using When and Return, but not when using Call.