Last active
November 24, 2020 04:01
-
-
Save antklim/984cceb1f33bce54c4697057e3a138f4 to your computer and use it in GitHub Desktop.
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 TestRemoteHandlerWithClientMock(t *testing.T) { | |
mockRes := &http.Response{ | |
StatusCode: http.StatusOK, | |
Body: ioutil.NopCloser(strings.NewReader(`{"foo": "bar"}`)), | |
} | |
clientMock := mocks.HTTPClient{} | |
clientMock.On("Do", mock.AnythingOfType("*http.Request")).Return(mockRes, nil) | |
req := httptest.NewRequest("GET", "/remote", nil) | |
rr := httptest.NewRecorder() | |
remoteHandler(&clientMock)(rr, req) | |
res := rr.Result() | |
resBody, _ := ioutil.ReadAll(res.Body) | |
assert.Equal(t, http.StatusOK, res.StatusCode) | |
assert.JSONEq(t, `{"foo": "bar"}`, string(resBody)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment