Closed mikepc closed 5 years ago
Hi Mike, did you close the issue because you found a solution?
Yes, and I apologize for posting it. Fundamentally I realized all I needed to do is ask the db what the values were, giving me a full integration test. That's why all of the mocks can't test args, it isn't the point of the library.
My java/C# instincts kicked in and I wanted to test the parameters passed in, but I shouldn't I guess. If you have any advice or code samples you feel would be relevant I would love them.
Thank you so much for responding!
On Fri, May 10, 2019 at 5:41 PM Elliot Chance notifications@github.com wrote:
Hi Mike, did you close the issue because you found a solution?
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/elliotchance/redismock/issues/7#issuecomment-491464919, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGWREY6KPV4P6U22B2PR4TPUYI4ZANCNFSM4HMDWBQQ .
I'm also curious in this. I'm assuming redismock doesn't directly support mocking redis.Pipeliner?
I generated my own mock for now using Mockery
mockery -dir %GOPATH%/src/github.com/go-redis/redis -name Pipeliner
And doing something like:
r := newTestRedis()
mockPipe := new(mocks.Pipeliner)
mockPipe.On("HGetAll", mock.Anything).Return(....) // pseudo code... fill in as normal
r.On("TxPipeline").Return(mockPipe)
` func (r PublishRequest) saveToRedis(b string) (ok bool) { q := r.keyConfig.QueueKey c := r.keyConfig.QueueChannel t := r.keyConfig.CacheKey rdb := r.rdb exp := time.Duration(r.cacheDurationSeconds)*time.Second pipe := rdb.TxPipeline()
}
`
Trying to unit test this function has been an adventure.
func (suite *PubSuite) TestSaveToRedis() { js, _ := suite.pr.packageMessage(suite.ob)
} `
I've stumbled through several issues, but I think I'm just missing something simple. Do you have any code samples that will test a TxPipeline?
The core issue I'm having is that the mock client returns a redis.TxPipeline instead of a mock Cmdable, and I understand it has to to meet the interface, but how should I go about making assertions on these calls?
Also, since all of the mocks are configured for 0 parameters, I'm finding it extremely troublesome to validate parameters being passed into them. How do I go about validating the parameters as well?