uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.82k stars 104 forks source link

MGet with go redis failing #94

Closed PhilAndrew closed 9 months ago

PhilAndrew commented 9 months ago

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

Triage Notes for the Maintainers

albaizzz commented 9 months ago

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 {