Skip to content

Commit

Permalink
tests: adds logs for unexpected status code. (#1037)
Browse files Browse the repository at this point in the history
* tests: adds logs for unexpected status code.

* chore: returns a meaningful error log.

* chore: makes lint happy

Co-authored-by: Matteo Pace <[email protected]>

* chore: fix var name

---------

Co-authored-by: Matteo Pace <[email protected]>
  • Loading branch information
jcchavezs and M4tteoP authored Apr 11, 2024
1 parent 650f02d commit 21c1deb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion http/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,30 @@ func Run(cfg Config) error {
resp, err := client.Do(req)
fmt.Printf("[Wait] Waiting for %s. Timeout: %ds\n", healthCheck.url, timeout)
if err == nil {
_, err = io.Copy(io.Discard, resp.Body)
if err != nil {
return err
}
resp.Body.Close()

if resp.StatusCode == healthCheck.expectedCode {
fmt.Printf("[Ok] Check successful, got status code %d\n", resp.StatusCode)
break
}

if healthCheck.expectedCode == configCheckStatusCode {
return fmt.Errorf("configs check failed, got status code %d, expected %d. Please check configs used", resp.StatusCode, healthCheck.expectedCode)
}

fmt.Printf("[Wait] Unexpected status code %d\n", resp.StatusCode)
}
timeout--
if timeout == 0 {
return fmt.Errorf("timeout waiting for response from %s, make sure the server is running. Last request error: %v", healthCheck.url, err)
if err != nil {
return fmt.Errorf("timeout waiting for response from %s, make sure the server is running. Last request error: %v", healthCheck.url, err)
}

return fmt.Errorf("timeout waiting for response from %s, unexpected status code", healthCheck.url)
}
}
}
Expand Down

0 comments on commit 21c1deb

Please sign in to comment.