Last active
November 23, 2020 21:13
-
-
Save antklim/ccb2c497c480a59c13ff3917d81409d2 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 TestRemoteHandlerWithStubServer(t *testing.T) { | |
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| w.WriteHeader(http.StatusServiceUnavailable) | |
| })) | |
| defer ts.Close() | |
| url := fmt.Sprintf("/remote?url=%s", ts.URL) | |
| req := httptest.NewRequest("GET", url, nil) | |
| rr := httptest.NewRecorder() | |
| remoteHandler(&http.Client{})(rr, req) | |
| res := rr.Result() | |
| resBody, _ := ioutil.ReadAll(res.Body) | |
| assert.Equal(t, http.StatusInternalServerError, res.StatusCode) | |
| assert.JSONEq(t, `{"message": "remote call failed, returned status code 503"}`, string(resBody)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment