elliotchance / redismock

🕋 Mocking Redis in unit tests in Go.
MIT License
147 stars 24 forks source link

Keys does not work when being mocked. #15

Open freshteapot opened 4 years ago

freshteapot commented 4 years ago

Using redisMock.On("Keys", "hello") fails and doesnt acknowledge the pattern sent in.

When I use "MatchedBy", it reports it as missing.

redisClient.On("Keys", mock.MatchedBy(func(input string) bool {
                fmt.Println(input)
                return true
            }))

When I use mock.Anything, it works.

Code for Keys doesnt send the pattern on to the Called. Below works.

func (m *ClientMock) Keys(pattern string) *redis.StringSliceCmd {
    if !m.hasStub("Keys") {
        return m.client.Keys(pattern)
    }
    return m.Called(pattern).Get(0).(*redis.StringSliceCmd)
}
elliotchance commented 4 years ago

Ah yes, this is a bug. If you have already fixed it please put in the PR.