-
Couldn't load subscription status.
- Fork 605
Setting mocked function's argument value #32
Description
I am trying to mock out a GroupCache(source at https://github.com/golang/groupcache) instance for testing and I am running into issues with the Get() call. GroupCache's Get function returns an error object but places the result of the Get into the third argument, dest, which is of type groupcache.Sink. Is there a way to mock a mutation of an argument in a function using gomock? I have tried using both Do and SetArg but I have been unable to produce the result I am looking for. This is a simplified example of what I am trying to do:
type GroupCache interface {
Get(ctx groupcache.Context, key string, dest groupcache.Sink) error
}
...
func TestGroupCacheMock(t *testing.T){
ctrl := gomock.NewController(t)
mockGroupCache := NewMockGroupCache(ctrl)
mockGroupCache.EXPECT().Get(gomock.Any()).Return(nil).AnyTimes() // This line is where I am unsure of what to do.
...
}
So in this example I want the mocked call to Get from my mocked GroupCache to return nil and set the dest variable to some arbitrary value.
Thanks!