I'm trying to write unit tests mocking service calls being made using GoMocks and It's been a real struggle.
One way I'm trying to simplify the code is to make a private method that gives a good response for all the mocks and then in each individual test that needs a different response of a mock call (e.g., testing a mock failure), I want to override that call with a different response.
e.g., of the setupMocks fn (scrubbed)
func setupMocks(s *SSAdapterV1Suite, userId string) {
s.mockDBDao.EXPECT().Mark(userId, gomock.Any()).
Return(nil)
s.mockDBDao.EXPECT().Get(userId).
Return(userData, nil)
s.mockDBDao.EXPECT().Delete(gomock.Any(), gomock.Any()).
Return(nil)
}
When I use the setupMocks fn in the "Success" scenario, it works fine.
However, if I try to use it in another unit test where I want to test how an error in the service call will get handled, gomocks will use the mockResponse setup in the setupMocks fn instead of the one which I wanted to override with.
Is there a call or something I can do in GoMocks to override a mock EXPECT()
response with something else instead of appending the callstack
?