Documentation ¶
Index ¶
- Constants
- func Do(timeout time.Duration, operation DoCondition) error
- func GetRequest(url string, timeout time.Duration, conditions ...ResponseCondition) error
- func Request(req *http.Request, timeout time.Duration, conditions ...ResponseCondition) error
- func Response(req *http.Request, timeout time.Duration) (*http.Response, error)
- func ResponseUntilStatusCode(req *http.Request, timeout time.Duration, statusCode int) (*http.Response, error)
- func Sleep(d time.Duration)
- type DoCondition
- type ResponseCondition
Constants ¶
const (
// CITimeoutMultiplier is the multiplier for all timeout in the CI
CITimeoutMultiplier = 3
)
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(timeout time.Duration, operation DoCondition) error
Do repeatedly executes an operation until no error condition occurs or the given timeout is reached, whatever comes first.
func GetRequest ¶
func GetRequest(url string, timeout time.Duration, conditions ...ResponseCondition) error
GetRequest is like Do, but runs a request against the given URL and applies the condition on the response. ResponseCondition may be nil, in which case only the request against the URL must succeed.
func Request ¶
Request is like Do, but runs a request against the given URL and applies the condition on the response. ResponseCondition may be nil, in which case only the request against the URL must succeed.
func Response ¶
Response is like Request, but returns the response for further processing at the call site. Conditions are not allowed since it would complicate signaling if the response body needs to be closed or not. Callers are expected to close on their own if the function returns a nil error.
func ResponseUntilStatusCode ¶
func ResponseUntilStatusCode(req *http.Request, timeout time.Duration, statusCode int) (*http.Response, error)
ResponseUntilStatusCode is like Request, but returns the response for further processing at the call site. Conditions are not allowed since it would complicate signaling if the response body needs to be closed or not. Callers are expected to close on their own if the function returns a nil error.
Types ¶
type DoCondition ¶
type DoCondition func() error
DoCondition is a retry condition function. It returns an error
type ResponseCondition ¶
ResponseCondition is a retry condition function. It receives a response, and returns an error if the response failed the condition.
func BodyContains ¶
func BodyContains(values ...string) ResponseCondition
BodyContains returns a retry condition function. The condition returns an error if the request body does not contain all the given strings.
func BodyContainsOr ¶
func BodyContainsOr(values ...string) ResponseCondition
BodyContainsOr returns a retry condition function. The condition returns an error if the request body does not contain one of the given strings.
func BodyNotContains ¶ added in v1.7.0
func BodyNotContains(values ...string) ResponseCondition
BodyNotContains returns a retry condition function. The condition returns an error if the request body contain one of the given strings.
func HasBody ¶
func HasBody() ResponseCondition
HasBody returns a retry condition function. The condition returns an error if the request body does not have body content.
func StatusCodeIs ¶
func StatusCodeIs(status int) ResponseCondition
StatusCodeIs returns a retry condition function. The condition returns an error if the given response's status code is not the given HTTP status code.