Skip to content

Commit

Permalink
chore(e2e): response body might fail
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tteoP committed Jul 26, 2023
1 parent 435d15a commit 7843e7a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions http/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,8 @@ func Run(cfg Config) error {
return fmt.Errorf("could not do http request: %v", err)
}

respBody, err := io.ReadAll(resp.Body)
respBody, errReadRespBody := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return fmt.Errorf("could not read response body: %v", err)
}

if test.expectedStatusCode != nil {
if err := test.expectedStatusCode(resp.StatusCode); err != nil {
Expand All @@ -289,6 +286,11 @@ func Run(cfg Config) error {
}

if test.expectedBody != nil {
// Same servers might aborting the request before sending the body (E.g. triggering a phase 3 rule with deny action)
// Therefore, we check if we properly read the body only if we expect a body to be received.
if errReadRespBody != nil {
return fmt.Errorf("could not read response body: %v", err)
}

Check warning on line 293 in http/e2e/e2e.go

View check run for this annotation

Codecov / codecov/patch

http/e2e/e2e.go#L292-L293

Added lines #L292 - L293 were not covered by tests
code, err := strconv.Atoi(resp.Header.Get("Content-Length"))
if err != nil {
return fmt.Errorf("could not convert content-length header to int: %v", err)
Expand Down

0 comments on commit 7843e7a

Please sign in to comment.