Beispiel #1
0
func TestWithStatusDefault(t *testing.T) {
	is := is.New(t)

	w := httptest.NewRecorder()
	r := newTestRequest()

	respond.WithStatus(w, r, http.StatusTeapot)

	is.Equal(http.StatusTeapot, w.Code)
	var data map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &data))
	is.Equal(data["status"], "I'm a teapot")
	is.Equal(data["code"], http.StatusTeapot)
	is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
}
Beispiel #2
0
func (t *testStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	respond.WithStatus(w, r, t.status)
}