Add tests for mismatching accept headers

This commit is contained in:
Jason McCallister 2017-10-23 22:41:44 -04:00 committed by GitHub
parent a06052dd83
commit c036316c9d
1 changed files with 16 additions and 0 deletions

View File

@ -84,3 +84,19 @@ func TestExampleHandler_get_list(t *testing.T) {
t.Fatalf("Expected a status of %d, got %d", e, a) t.Fatalf("Expected a status of %d, got %d", e, a)
} }
} }
func TestHttpErrorWhenHeaderDoesNotMatch(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "/blogs", nil)
if err != nil {
t.Fatal(err)
}
r.Header.Set(headerAccept, "application/xml")
rr := httptest.NewRecorder()
handler := &ExampleHandler{}
handler.ServeHTTP(rr, r)
if rr.Code != http.StatusUnsupportedMediaType {
t.Fatal("expected Unsupported Media Type staus error")
}
}