Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active November 23, 2020 21:13
Show Gist options
  • Select an option

  • Save antklim/ccb2c497c480a59c13ff3917d81409d2 to your computer and use it in GitHub Desktop.

Select an option

Save antklim/ccb2c497c480a59c13ff3917d81409d2 to your computer and use it in GitHub Desktop.
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