From c036316c9d026730810b91249af6657b7e06e236 Mon Sep 17 00:00:00 2001 From: Jason McCallister Date: Mon, 23 Oct 2017 22:41:44 -0400 Subject: [PATCH] Add tests for mismatching accept headers --- examples/handler_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/handler_test.go b/examples/handler_test.go index b50dc04..b9a5b3d 100644 --- a/examples/handler_test.go +++ b/examples/handler_test.go @@ -84,3 +84,19 @@ func TestExampleHandler_get_list(t *testing.T) { 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") + } +}