Created
October 22, 2020 11:09
-
-
Save Gyvastis/c04163e2b8a7c71b368631b3b422ec76 to your computer and use it in GitHub Desktop.
golang testify return on consecutive calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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