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 RequestWithTransport(req *http.Request, timeout time.Duration, transport *http.Transport, ...) 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
- func BodyContains(values ...string) ResponseCondition
- func BodyContainsOr(values ...string) ResponseCondition
- func BodyNotContains(values ...string) ResponseCondition
- func HasBody() ResponseCondition
- func HasCn(cn string) ResponseCondition
- func HasHeader(header string) ResponseCondition
- func HasHeaderStruct(header http.Header) ResponseCondition
- func HasHeaderValue(header, value string, exactMatch bool) ResponseCondition
- func StatusCodeIs(status int) 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 RequestWithTransport ¶ added in v1.6.6
func RequestWithTransport(req *http.Request, timeout time.Duration, transport *http.Transport, conditions ...ResponseCondition) error
RequestWithTransport 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.5.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 HasCn ¶ added in v1.6.6
func HasCn(cn string) ResponseCondition
HasCn returns a retry condition function. The condition returns an error if the cn is not correct.
func HasHeader ¶
func HasHeader(header string) ResponseCondition
HasHeader returns a retry condition function. The condition returns an error if the response does not have a header set.
func HasHeaderStruct ¶
func HasHeaderStruct(header http.Header) ResponseCondition
HasHeaderStruct returns a retry condition function. The condition returns an error if the response does contain the headers set, and matching contents.
func HasHeaderValue ¶
func HasHeaderValue(header, value string, exactMatch bool) ResponseCondition
HasHeaderValue returns a retry condition function. The condition returns an error if the response does not have a header set, and a value for that header. Has an option to test for an exact header match only, not just contains.
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.