示例#1
0
func TestErrorJSON(t *testing.T) {
	assert := assert.New(t)
	e := errors.New("test")
	w := httptest.NewRecorder()
	req, err := http.NewRequest("POST", "/test", nil)
	assert.NoError(err)
	err = shttp.Error(w, req, e, 200)
	assert.NoError(err)
	assert.Equal(w.Code, 200, "should be expected status code")
	assert.Contains(w.Body.String(), `"description":"test"`, "should be formatted as JSON error")
}
示例#2
0
func TestErrorXML(t *testing.T) {
	assert := assert.New(t)
	e := errors.New("test")
	w := httptest.NewRecorder()
	req, err := http.NewRequest("POST", "/test", nil)
	assert.NoError(err)
	req.Header.Set("Accept", "application/xml")
	err = shttp.Error(w, req, e, 503)
	assert.NoError(err)
	assert.Equal(w.Code, 503, "should be expected status code")
	assert.Contains(w.Body.String(), "<title>Service Unavailable</title>")
}