httpexpect icon indicating copy to clipboard operation
httpexpect copied to clipboard

Add `WithRetryHandler` for a custom `RetryPolicy`

Open acouvreur opened this issue 9 months ago • 6 comments

Context: My test is as simple as:

e.GET("/nginx").
		WithMaxRetries(10).
		WithRetryDelay(time.Second, time.Second*2).
		WithRetryPolicy(httpexpect.RetryAllErrors).
		Expect().
		Status(http.StatusNotFound).
		Body().Contains(`nginx/`)

I'm expecting a dynamic result from one call to the other. And I'd like to handle the retry policy myself here. Whuch does not seems doable right now.

So something like:

e.GET("/nginx").
		WithMaxRetries(10).
		WithRetryDelay(time.Second, time.Second*2).
		WithRetryPolicy(httpexpect.RetryAllErrors).
		WithRetryHandler(func(resp *http.Response, err error) bool {
			// Check body if available, etc.
			return ...
		})
		Expect().
		Status(http.StatusNotFound).
		Body().Contains(`nginx/`)

What do you think ?

acouvreur avatar Sep 13 '23 21:09 acouvreur