Skip to content

Commit 03a5534

Browse files
committed
fix for handler test
1 parent c9ef1d5 commit 03a5534

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

examples/handler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ func (h *ExampleHandler) updateBlog(w http.ResponseWriter, r *http.Request) {
6969

7070
blog := new(Blog)
7171

72-
if r.Body == nil {
73-
http.Error(w, "request body cannot be empty", http.StatusBadRequest)
74-
return
75-
}
76-
7772
if err := jsonapiRuntime.UnmarshalPayload(r.Body, blog); err != nil {
7873
http.Error(w, err.Error(), http.StatusInternalServerError)
7974
return

examples/handler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestHttpErrorWhenHeaderDoesNotMatch(t *testing.T) {
102102
}
103103

104104
func TestHttpErrorWhenMethodDoesNotMatch(t *testing.T) {
105-
r, err := http.NewRequest(http.MethodPatch, "/blogs", nil)
105+
r, err := http.NewRequest(http.MethodOptions, "/blogs", nil)
106106
if err != nil {
107107
t.Fatal(err)
108108
}
@@ -112,7 +112,7 @@ func TestHttpErrorWhenMethodDoesNotMatch(t *testing.T) {
112112
handler := &ExampleHandler{}
113113
handler.ServeHTTP(rr, r)
114114

115-
if rr.Code != http.StatusBadRequest {
116-
t.Fatalf("expected HTTP Status Bad Request (400), got %d", rr.Code)
115+
if rr.Code != http.StatusNotFound {
116+
t.Fatal("expected HTTP Status Not Found status error")
117117
}
118118
}

0 commit comments

Comments
 (0)