HTTPGetWithRetry performs an HTTP GET on an `endpoint`, using retryDelay also as a request timeout. In the case of an error or the response status is not the expected one, it retries the same request, returning the response body as a string (empty if we could not reach it)
( t testing.TB, endpoint string, expectedStatus int, retryDelay time.Duration, timeout time.Duration, )
| 479 | // In the case of an error or the response status is not the expected one, it retries the same request, |
| 480 | // returning the response body as a string (empty if we could not reach it) |
| 481 | func HTTPGetWithRetry( |
| 482 | t testing.TB, |
| 483 | endpoint string, |
| 484 | expectedStatus int, |
| 485 | retryDelay time.Duration, |
| 486 | timeout time.Duration, |
| 487 | ) string { |
| 488 | t.Helper() |
| 489 | var ( |
| 490 | r *http.Response |
| 491 | err error |
| 492 | ) |
| 493 | client := &http.Client{ |
| 494 | Timeout: retryDelay, |
| 495 | } |
| 496 | fmt.Printf("\t[%s] GET %s\n", t.Name(), endpoint) |
| 497 | checkUp := func(t poll.LogT) poll.Result { |
| 498 | r, err = client.Get(endpoint) |
| 499 | if err != nil { |
| 500 | return poll.Continue("reaching %q: Error %s", endpoint, err.Error()) |
| 501 | } |
| 502 | if r.StatusCode == expectedStatus { |
| 503 | return poll.Success() |
| 504 | } |
| 505 | return poll.Continue("reaching %q: %d != %d", endpoint, r.StatusCode, expectedStatus) |
| 506 | } |
| 507 | poll.WaitOn(t, checkUp, poll.WithDelay(retryDelay), poll.WithTimeout(timeout)) |
| 508 | if r != nil { |
| 509 | b, err := io.ReadAll(r.Body) |
| 510 | assert.NilError(t, err) |
| 511 | return string(b) |
| 512 | } |
| 513 | return "" |
| 514 | } |
| 515 | |
| 516 | func (c *CLI) cleanupWithDown(t testing.TB, project string, args ...string) { |
| 517 | t.Helper() |