Skip to content

Commit 21c1deb

Browse files
jcchavezsM4tteoP
andauthored
tests: adds logs for unexpected status code. (#1037)
* 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]>
1 parent 650f02d commit 21c1deb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

http/e2e/e2e.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,30 @@ func Run(cfg Config) error {
254254
resp, err := client.Do(req)
255255
fmt.Printf("[Wait] Waiting for %s. Timeout: %ds\n", healthCheck.url, timeout)
256256
if err == nil {
257+
_, err = io.Copy(io.Discard, resp.Body)
258+
if err != nil {
259+
return err
260+
}
257261
resp.Body.Close()
262+
258263
if resp.StatusCode == healthCheck.expectedCode {
259264
fmt.Printf("[Ok] Check successful, got status code %d\n", resp.StatusCode)
260265
break
261266
}
267+
262268
if healthCheck.expectedCode == configCheckStatusCode {
263269
return fmt.Errorf("configs check failed, got status code %d, expected %d. Please check configs used", resp.StatusCode, healthCheck.expectedCode)
264270
}
271+
272+
fmt.Printf("[Wait] Unexpected status code %d\n", resp.StatusCode)
265273
}
266274
timeout--
267275
if timeout == 0 {
268-
return fmt.Errorf("timeout waiting for response from %s, make sure the server is running. Last request error: %v", healthCheck.url, err)
276+
if err != nil {
277+
return fmt.Errorf("timeout waiting for response from %s, make sure the server is running. Last request error: %v", healthCheck.url, err)
278+
}
279+
280+
return fmt.Errorf("timeout waiting for response from %s, unexpected status code", healthCheck.url)
269281
}
270282
}
271283
}

0 commit comments

Comments
 (0)