Skip to content

Commit

Permalink
test: check status code before reading the body
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jan 20, 2025
1 parent afa68c7 commit ebb19b0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/e2e/libhvee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func get(endpoint string) ([]byte, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
Fail(fmt.Sprintf("get %s: status code: %d", endpoint, resp.StatusCode))
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
return body, err
Expand All @@ -46,6 +49,9 @@ func pullWithProgress(endpoint string, dst *os.File) error {
if err != nil {
Fail(err.Error())
}
if resp.StatusCode != http.StatusOK {
Fail(fmt.Sprintf("get %s: status code: %d", endpoint, resp.StatusCode))
}
defer resp.Body.Close()
return doWithProgress("downloading", resp.Body, dst, resp.ContentLength)
}
Expand Down

0 comments on commit ebb19b0

Please sign in to comment.