Skip to content

Commit

Permalink
test: refactor response handling and add response code assertion
Browse files Browse the repository at this point in the history
- Remove the lines that close the response body and get the status code from the response body
- Add an assertion to check the response code using the `w.Code` field

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Nov 25, 2023
1 parent eab81f0 commit 40e155c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ func TestWriter_Status(t *testing.T) {

r.ServeHTTP(w, req)

// Close the response body
defer w.Result().Body.Close()
code := w.Result().StatusCode
assert.Equal(t, http.StatusInternalServerError, code)
assert.Equal(t, http.StatusInternalServerError, w.Code)
assert.Equal(t, strconv.Itoa(http.StatusInternalServerError), req.Header.Get("X-Status-Code-MW-Set"))
}

Expand Down

0 comments on commit 40e155c

Please sign in to comment.