Skip to content

Instantly share code, notes, and snippets.

@Gyvastis
Created October 22, 2020 11:09
Show Gist options
  • Save Gyvastis/c04163e2b8a7c71b368631b3b422ec76 to your computer and use it in GitHub Desktop.
Save Gyvastis/c04163e2b8a7c71b368631b3b422ec76 to your computer and use it in GitHub Desktop.
golang testify return on consecutive calls
func() {
consecutive := -1
responseMocks := []string{
responseString1,
responseString2,
}
httpClientMock.On("SendRequest", req).Return(func() *http.Response {
consecutive++
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(responseMocks[consecutive]))),
}
}, nil).Twice()
}
func (c HttpClientMock) SendRequest(req *http.Request) (*http.Response, error) {
args := c.Called(req)
fnc := args.Get(0).(func() *http.Response)
return fnc(), args.Error(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment