Skip to content

Commit

Permalink
refactor: refactor error handling and response assertions
Browse files Browse the repository at this point in the history
- Remove the assertion for the response status code being equal to `http.StatusInternalServerError`
- Add a defer statement to close the response body
- Add an assertion for the response status code being equal to `http.StatusInternalServerError`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Nov 24, 2023
1 parent df5d291 commit 09305e3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func TestWriter_Status(t *testing.T) {

r.ServeHTTP(w, req)

assert.Equal(t, w.Result().StatusCode, http.StatusInternalServerError)
// Close the response body
defer w.Result().Body.Close()
assert.Equal(t, http.StatusInternalServerError, w.Result().StatusCode)

Check failure on line 135 in timeout_test.go

View workflow job for this annotation

GitHub Actions / lint

response body must be closed (bodyclose)
assert.Equal(t, strconv.Itoa(http.StatusInternalServerError), req.Header.Get("X-Status-Code-MW-Set"))
}

Expand Down

0 comments on commit 09305e3

Please sign in to comment.