Comparting a float with NaN is always false so the assertion would always pass.
Added a check that either the actual or expected values are NaN.
InDelta will now fail if either the actual or expected value are NaN.
We cannot compare two Func arguments to check if they are equal using
the reflect package. This leads to the following misleading panic:
```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/", handler)
muxMock.HandleFunc("/", handler)
// panics arguing handler != handler
```
Since we cannot fix this behaviour using reflection, this patch
provides a better panic with a meaningful workaround.
```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/", handler)
// panics recommending defining the expectatin with:
// AnythingOfType("func(http.ResponseWriter, *http.Request)")
```
Solution following the panic's instructions:
```go
handler := func(http.ResponseWriter, *http.Request) {}
muxMock.On("HandleFunc", "/",
mock.AnythingOfType("func(http.ResponseWriter, *http.Request)"))
muxMock.HandleFunc("/", handler)
```
Some methods in Go take a pointer to a struct or a map and are supposed
to set some values in the referenced argument. Using Return is not
enough to mock such methods.
We are introducing a Run method that allows setting a Call handler to
make your mock update such referenced values.
Example usage mocking a service that finds a user in a data store and
fills the values in the provided struct:
```go
m.On("Find", 1, mock.AnythingOfType(*User))
.Return(nil)
.Run(func(args mock.Arguments) {
u := args.Get(0).(*User)
u.ID = 1
u.Email = "mail@example.com"
})
```
You sometimes want to test concurrent behaviour like timeouts, but it
was not currently possible with our mocks.
This commits adds the following functions to Mock:
`After` will block m.Called for the given duration before returning.
```golang
func (m *Mock) After(d time.Duration) *Mock
Mock.On("MyMethod", arg1).After(1 * time.Millisecond)
```
`WaitUntil` is the primitive under `After`, and it's exposed in case you
want somebody wants more control over the returns. `Called` blocks until the w
channel is closed or receives a message.
```golang
func (m *Mock) WaitUntil(w <-chan time.Time) *Mock
Mock.On("MyMethod", arg1).WaitUntil(time.After(1 * time.Millisecond))
```
`ObjectsAreEqual` using `ConvertibleTo` causes the `ObjectsAreEqual`
function to be asymmetrical and producing incorrect assertions.
Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
in `ObjectsAreEqual`, `expectedValue.Convert(actualType)` was being called when
`actualType.ConvertibleTo(reflect.TypeOf(expected))` was true. This was a problem
for situations such as when expected was an int and actual was a string, since
ints are `ConvertibleTo` strings, but the reverse is not true.
Changing the ConvertibleTo check to `expectedValue.Type().ConvertibleTo(actualType)`
solves the issue.