uber-go/mock

MGet with go redis failing

PhilAndrew opened this issue · 1 comments

Actual behavior The unit test at https://github.com/PhilAndrew/mockgenredisv9/blob/main/mock_v9/redis_cache_v2_test.go#L36 should pass as it takes and supplies 3 parameters. Instead it says wrong number of arguments in DoAndReturn func for *mock_v9.MockCmdable.MGet: got 3, want 2. This suggests there is a bug in mockgen where it is not compatible with Redis v9 for the MGet method https://github.com/redis/go-redis
I tried modifying the number of parameters but that didn't work.

Expected behavior I expect the unit test at this github repo to pass. https://github.com/PhilAndrew/mockgenredisv9

To Reproduce Steps to reproduce the behavior

Git clone https://github.com/PhilAndrew/mockgenredisv9 and run go test -cover ./...

Additional Information

  • gomock mode (reflect or source):I generated source
  • gomock version or git ref:Latest version v0.3.0
  • golang version:1.20

Triage Notes for the Maintainers

refer from this sample about variadic parameter handling in gomock https://github.com/golang/mock/blob/main/mockgen/internal/tests/generated_identifier_conflict/bugreport_test.go
The solution is you should change
mockRedis.EXPECT().MGet(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(context context.Context, cacheKey string, deleteKey string) *redis.SliceCmd {
to >
mockRedis.EXPECT().MGet(gomock.Any(), gomock.Any()).DoAndReturn(func(context context.Context, args ...string) *redis.SliceCmd {