Skip to content

Commit

Permalink
Fix potential panic by handling error on Close
Browse files Browse the repository at this point in the history
Add a deferred anonymous function to properly handle errors when closing the response body in tests/main_test.go. This change prevents unhandled errors that might occur during the closing of the HTTP response body.
  • Loading branch information
PiotrFerenc committed Jul 26, 2024
1 parent 8b584b7 commit 612ccb6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func TestProcess(t *testing.T) {
if err != nil {
require.NoError(t, err)
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
panic(err)
}
}(resp.Body)
require.Equal(t, http.StatusOK, resp.StatusCode)

body, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 612ccb6

Please sign in to comment.