Skip to content

Commit c036316

Browse files
Add tests for mismatching accept headers
1 parent a06052d commit c036316

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/handler_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,19 @@ func TestExampleHandler_get_list(t *testing.T) {
8484
t.Fatalf("Expected a status of %d, got %d", e, a)
8585
}
8686
}
87+
88+
func TestHttpErrorWhenHeaderDoesNotMatch(t *testing.T) {
89+
r, err := http.NewRequest(http.MethodGet, "/blogs", nil)
90+
if err != nil {
91+
t.Fatal(err)
92+
}
93+
r.Header.Set(headerAccept, "application/xml")
94+
95+
rr := httptest.NewRecorder()
96+
handler := &ExampleHandler{}
97+
handler.ServeHTTP(rr, r)
98+
99+
if rr.Code != http.StatusUnsupportedMediaType {
100+
t.Fatal("expected Unsupported Media Type staus error")
101+
}
102+
}

0 commit comments

Comments
 (0)