Skip to content

Commit

Permalink
Merge pull request #118 from themccallister/patch-1
Browse files Browse the repository at this point in the history
Add tests for mismatching accept headers
  • Loading branch information
shwoodard authored Nov 8, 2017
2 parents a06052d + 081fb8a commit e0fc4ee
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,35 @@ 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")
}
}

func TestHttpErrorWhenMethodDoesNotMatch(t *testing.T) {
r, err := http.NewRequest(http.MethodPatch, "/blogs", nil)
if err != nil {
t.Fatal(err)
}
r.Header.Set(headerAccept, jsonapi.MediaType)

rr := httptest.NewRecorder()
handler := &ExampleHandler{}
handler.ServeHTTP(rr, r)

if rr.Code != http.StatusNotFound {
t.Fatal("expected HTTP Status Not Found status error")
}
}

0 comments on commit e0fc4ee

Please sign in to comment.