Documentation
¶
Overview ¶
Package httphelper contains helpers to interact with deployed resources through HTTP.
Index ¶
- func ContinuouslyCheckURLContext(t testing.TestingT, ctx context.Context, url string, stopChecking <-chan bool, ...) (*sync.WaitGroup, <-chan GetResponse)
- func HTTPDoContext(t testing.TestingT, ctx context.Context, method string, url string, ...) (int, string)
- func HTTPDoContextE(t testing.TestingT, ctx context.Context, method string, url string, ...) (int, string, error)
- func HTTPDoWithCustomValidationContext(t testing.TestingT, ctx context.Context, method string, url string, ...)
- func HTTPDoWithCustomValidationContextE(t testing.TestingT, ctx context.Context, method string, url string, ...) error
- func HTTPDoWithCustomValidationWithOptions(t testing.TestingT, options HttpDoOptions, ...)
- func HTTPDoWithCustomValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, ...) error
- func HTTPDoWithOptions(t testing.TestingT, options HttpDoOptions) (int, string)
- func HTTPDoWithOptionsE(t testing.TestingT, options HttpDoOptions) (int, string, error)
- func HTTPDoWithRetryContext(t testing.TestingT, ctx context.Context, method string, url string, ...) string
- func HTTPDoWithRetryContextE(t testing.TestingT, ctx context.Context, method string, url string, ...) (string, error)
- func HTTPDoWithRetryWithOptions(t testing.TestingT, options HttpDoOptions, expectedStatus int, retries int, ...) string
- func HTTPDoWithRetryWithOptionsE(t testing.TestingT, options HttpDoOptions, expectedStatus int, retries int, ...) (string, error)
- func HTTPDoWithValidationContext(t testing.TestingT, ctx context.Context, method string, url string, ...)
- func HTTPDoWithValidationContextE(t testing.TestingT, ctx context.Context, method string, url string, ...) error
- func HTTPDoWithValidationRetryContext(t testing.TestingT, ctx context.Context, method string, url string, ...)
- func HTTPDoWithValidationRetryContextE(t testing.TestingT, ctx context.Context, method string, url string, ...) error
- func HTTPDoWithValidationRetryWithOptions(t testing.TestingT, options HttpDoOptions, expectedStatus int, ...)
- func HTTPDoWithValidationRetryWithOptionsE(t testing.TestingT, options HttpDoOptions, expectedStatus int, ...) error
- func HTTPDoWithValidationWithOptions(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, ...)
- func HTTPDoWithValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, ...) error
- func HTTPGetContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config) (int, string)
- func HTTPGetContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config) (int, string, error)
- func HTTPGetWithCustomValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...)
- func HTTPGetWithCustomValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...) error
- func HTTPGetWithRetryContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...)
- func HTTPGetWithRetryContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...) error
- func HTTPGetWithRetryWithCustomValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...)
- func HTTPGetWithRetryWithCustomValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...) error
- func HTTPGetWithValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...)
- func HTTPGetWithValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, ...) error
- func HttpGetWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, ...)
- func HttpGetWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, ...) error
- func HttpGetWithOptions(t testing.TestingT, options HttpGetOptions) (int, string)
- func HttpGetWithOptionsE(t testing.TestingT, options HttpGetOptions) (int, string, error)
- func HttpGetWithRetryWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, retries int, ...)
- func HttpGetWithRetryWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, retries int, ...) error
- func HttpGetWithRetryWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatus int, ...)
- func HttpGetWithRetryWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatus int, ...) error
- func HttpGetWithValidationWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, ...)
- func HttpGetWithValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, ...) error
- func RunDummyServerContext(t testing.TestingT, ctx context.Context, text string) (net.Listener, int)
- func RunDummyServerContextE(t testing.TestingT, ctx context.Context, text string) (net.Listener, int, error)
- func RunDummyServerWithHandlersContext(t testing.TestingT, ctx context.Context, ...) (net.Listener, int)
- func RunDummyServerWithHandlersContextE(t testing.TestingT, ctx context.Context, ...) (net.Listener, int, error)
- type GetResponse
- type HttpDoOptions
- type HttpGetOptions
- type ValidationFunctionFailed
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContinuouslyCheckURLContext ¶
func ContinuouslyCheckURLContext( t testing.TestingT, ctx context.Context, url string, stopChecking <-chan bool, sleepBetweenChecks time.Duration, ) (*sync.WaitGroup, <-chan GetResponse)
ContinuouslyCheckURLContext continuously checks the given URL at the specified interval until the stopChecking channel receives a signal to stop. It returns a sync.WaitGroup that can be used to wait for the checking to stop, and a read-only channel to stream the responses for each check. The channel has a buffer of 1000 entries, after which it will start to drop send events. The provided context is used for each HTTP request made during checking.
func HTTPDoContext ¶
func HTTPDoContext( t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, tlsConfig *tls.Config, ) (int, string)
HTTPDoContext performs the given HTTP method on the given URL and returns the HTTP status code and body. The provided context is used for the HTTP request. If there's any error, fail the test.
func HTTPDoContextE ¶
func HTTPDoContextE( t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, tlsConfig *tls.Config, ) (int, string, error)
HTTPDoContextE performs the given HTTP method on the given URL and returns the HTTP status code, body, and any error. The provided context is used for the HTTP request.
func HTTPDoWithCustomValidationContext ¶
func HTTPDoWithCustomValidationContext(t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool, tlsConfig *tls.Config)
HTTPDoWithCustomValidationContext performs the given HTTP method on the given URL and validates the returned status code and body using the given function. The provided context is used for the HTTP request.
func HTTPDoWithCustomValidationContextE ¶
func HTTPDoWithCustomValidationContextE(t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool, tlsConfig *tls.Config) error
HTTPDoWithCustomValidationContextE performs the given HTTP method on the given URL and validates the returned status code and body using the given function. The provided context is used for the HTTP request.
func HTTPDoWithCustomValidationWithOptions ¶
func HTTPDoWithCustomValidationWithOptions(t testing.TestingT, options HttpDoOptions, validateResponse func(int, string) bool)
HTTPDoWithCustomValidationWithOptions performs the given HTTP method on the given URL and validate the returned status code and body using the given function.
func HTTPDoWithCustomValidationWithOptionsE ¶
func HTTPDoWithCustomValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, validateResponse func(int, string) bool) error
HTTPDoWithCustomValidationWithOptionsE performs the given HTTP method on the given URL and validate the returned status code and body using the given function.
func HTTPDoWithOptions ¶
func HTTPDoWithOptions( t testing.TestingT, options HttpDoOptions, ) (int, string)
HTTPDoWithOptions performs the given HTTP method on the given URL and return the HTTP status code and body. If there's any error, fail the test.
func HTTPDoWithOptionsE ¶
HTTPDoWithOptionsE performs the given HTTP method on the given URL and return the HTTP status code, body, and any error.
func HTTPDoWithRetryContext ¶
func HTTPDoWithRetryContext( t testing.TestingT, ctx context.Context, method string, url string, body []byte, headers map[string]string, expectedStatus int, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) string
HTTPDoWithRetryContext repeatedly performs the given HTTP method on the given URL until the given status code is returned or until max retries has been exceeded. The provided context is used for each HTTP request. The function compares the expected status code against the received one and fails if they don't match.
func HTTPDoWithRetryContextE ¶
func HTTPDoWithRetryContextE( t testing.TestingT, ctx context.Context, method string, url string, body []byte, headers map[string]string, expectedStatus int, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) (string, error)
HTTPDoWithRetryContextE repeatedly performs the given HTTP method on the given URL until the given status code is returned or until max retries has been exceeded. The provided context is used for each HTTP request. The function compares the expected status code against the received one and fails if they don't match.
func HTTPDoWithRetryWithOptions ¶
func HTTPDoWithRetryWithOptions( t testing.TestingT, options HttpDoOptions, expectedStatus int, retries int, sleepBetweenRetries time.Duration, ) string
HTTPDoWithRetryWithOptions repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded. The function compares the expected status code against the received one and fails if they don't match.
func HTTPDoWithRetryWithOptionsE ¶
func HTTPDoWithRetryWithOptionsE( t testing.TestingT, options HttpDoOptions, expectedStatus int, retries int, sleepBetweenRetries time.Duration, ) (string, error)
HTTPDoWithRetryWithOptionsE repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded. The function compares the expected status code against the received one and fails if they don't match.
func HTTPDoWithValidationContext ¶
func HTTPDoWithValidationContext(t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string, tlsConfig *tls.Config)
HTTPDoWithValidationContext performs the given HTTP method on the given URL and verifies that the response has the expected status code and body. The provided context is used for the HTTP request. If either doesn't match, fail the test.
func HTTPDoWithValidationContextE ¶
func HTTPDoWithValidationContextE(t testing.TestingT, ctx context.Context, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string, tlsConfig *tls.Config) error
HTTPDoWithValidationContextE performs the given HTTP method on the given URL and verifies that the response has the expected status code and body. The provided context is used for the HTTP request. If either doesn't match, return an error.
func HTTPDoWithValidationRetryContext ¶
func HTTPDoWithValidationRetryContext( t testing.TestingT, ctx context.Context, method string, url string, body []byte, headers map[string]string, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, )
HTTPDoWithValidationRetryContext repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPDoWithValidationRetryContextE ¶
func HTTPDoWithValidationRetryContextE( t testing.TestingT, ctx context.Context, method string, url string, body []byte, headers map[string]string, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) error
HTTPDoWithValidationRetryContextE repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPDoWithValidationRetryWithOptions ¶
func HTTPDoWithValidationRetryWithOptions( t testing.TestingT, options HttpDoOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, )
HTTPDoWithValidationRetryWithOptions repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded.
func HTTPDoWithValidationRetryWithOptionsE ¶
func HTTPDoWithValidationRetryWithOptionsE( t testing.TestingT, options HttpDoOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, ) error
HTTPDoWithValidationRetryWithOptionsE repeatedly performs the given HTTP method on the given URL until the given status code and body are returned or until max retries has been exceeded.
func HTTPDoWithValidationWithOptions ¶
func HTTPDoWithValidationWithOptions(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, expectedBody string)
HTTPDoWithValidationWithOptions performs the given HTTP method on the given URL and verify that you get back the expected status code and body. If either doesn't match, fail the test.
func HTTPDoWithValidationWithOptionsE ¶
func HTTPDoWithValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, expectedBody string) error
HTTPDoWithValidationWithOptionsE performs the given HTTP method on the given URL and verify that you get back the expected status code and body. If either doesn't match, return an error.
func HTTPGetContext ¶
func HTTPGetContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config) (int, string)
HTTPGetContext performs an HTTP GET on the given URL with an optional custom TLS configuration and returns the HTTP status code and body. The provided context is used for the HTTP request. If there's any error, fail the test.
func HTTPGetContextE ¶
func HTTPGetContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config) (int, string, error)
HTTPGetContextE performs an HTTP GET on the given URL with an optional custom TLS configuration and returns the HTTP status code, body, and any error. The provided context is used for the HTTP request.
func HTTPGetWithCustomValidationContext ¶
func HTTPGetWithCustomValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool)
HTTPGetWithCustomValidationContext performs an HTTP GET on the given URL and validates the returned status code and body using the given function. The provided context is used for the HTTP request.
func HTTPGetWithCustomValidationContextE ¶
func HTTPGetWithCustomValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool) error
HTTPGetWithCustomValidationContextE performs an HTTP GET on the given URL and validates the returned status code and body using the given function. The provided context is used for the HTTP request.
func HTTPGetWithRetryContext ¶
func HTTPGetWithRetryContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration)
HTTPGetWithRetryContext repeatedly performs an HTTP GET on the given URL until the given status code and body are returned or until max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPGetWithRetryContextE ¶
func HTTPGetWithRetryContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) error
HTTPGetWithRetryContextE repeatedly performs an HTTP GET on the given URL until the given status code and body are returned or until max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPGetWithRetryWithCustomValidationContext ¶
func HTTPGetWithRetryWithCustomValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool)
HTTPGetWithRetryWithCustomValidationContext repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPGetWithRetryWithCustomValidationContextE ¶
func HTTPGetWithRetryWithCustomValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) error
HTTPGetWithRetryWithCustomValidationContextE repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded. The provided context is used for each HTTP request.
func HTTPGetWithValidationContext ¶
func HTTPGetWithValidationContext(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string)
HTTPGetWithValidationContext performs an HTTP GET on the given URL and verifies that the response has the expected status code and body. The provided context is used for the HTTP request. If either doesn't match, fail the test.
func HTTPGetWithValidationContextE ¶
func HTTPGetWithValidationContextE(t testing.TestingT, ctx context.Context, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string) error
HTTPGetWithValidationContextE performs an HTTP GET on the given URL and verifies that the response has the expected status code and body. The provided context is used for the HTTP request. If either doesn't match, return an error.
func HttpGetWithCustomValidationWithOptions ¶
func HttpGetWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, validateResponse func(int, string) bool)
HttpGetWithCustomValidationWithOptions performs an HTTP GET on the given URL and validate the returned status code and body using the given function.
func HttpGetWithCustomValidationWithOptionsE ¶
func HttpGetWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, validateResponse func(int, string) bool) error
HttpGetWithCustomValidationWithOptionsE performs an HTTP GET on the given URL and validate the returned status code and body using the given function.
func HttpGetWithOptions ¶
func HttpGetWithOptions(t testing.TestingT, options HttpGetOptions) (int, string)
HttpGetWithOptions performs an HTTP GET, with an optional pointer to a custom TLS configuration, on the given URL and return the HTTP status code and body. If there's any error, fail the test.
func HttpGetWithOptionsE ¶
HttpGetWithOptionsE performs an HTTP GET on the given URL with the given options and returns the HTTP status code, body, and any error.
func HttpGetWithRetryWithCustomValidationWithOptions ¶
func HttpGetWithRetryWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool)
HttpGetWithRetryWithCustomValidationWithOptions repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded.
func HttpGetWithRetryWithCustomValidationWithOptionsE ¶
func HttpGetWithRetryWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) error
HttpGetWithRetryWithCustomValidationWithOptionsE repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded.
func HttpGetWithRetryWithOptions ¶
func HttpGetWithRetryWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration)
HttpGetWithRetryWithOptions repeatedly performs an HTTP GET on the given URL until the given status code and body are returned or until max retries has been exceeded.
func HttpGetWithRetryWithOptionsE ¶
func HttpGetWithRetryWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) error
HttpGetWithRetryWithOptionsE repeatedly performs an HTTP GET on the given URL until the given status code and body are returned or until max retries has been exceeded.
func HttpGetWithValidationWithOptions ¶
func HttpGetWithValidationWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, expectedBody string)
HttpGetWithValidationWithOptions performs an HTTP GET on the given URL and verify that you get back the expected status code and body. If either doesn't match, fail the test.
func HttpGetWithValidationWithOptionsE ¶
func HttpGetWithValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, expectedBody string) error
HttpGetWithValidationWithOptionsE performs an HTTP GET on the given URL and verify that you get back the expected status code and body. If either doesn't match, return an error.
func RunDummyServerContext ¶
func RunDummyServerContext(t testing.TestingT, ctx context.Context, text string) (net.Listener, int)
RunDummyServerContext runs a dummy HTTP server on a unique port that will return the given text. Returns the Listener for the server, the port it's listening on, or an error if something went wrong while trying to start the listener. The provided context is used when establishing the network listener. Make sure to call the Close() method on the Listener when you're done!
func RunDummyServerContextE ¶
func RunDummyServerContextE(t testing.TestingT, ctx context.Context, text string) (net.Listener, int, error)
RunDummyServerContextE runs a dummy HTTP server on a unique port that will return the given text. Returns the Listener for the server, the port it's listening on, or an error if something went wrong while trying to start the listener. The provided context is used when establishing the network listener. Make sure to call the Close() method on the Listener when you're done!
func RunDummyServerWithHandlersContext ¶
func RunDummyServerWithHandlersContext(t testing.TestingT, ctx context.Context, handlers map[string]func(http.ResponseWriter, *http.Request)) (net.Listener, int)
RunDummyServerWithHandlersContext runs a dummy HTTP server on a unique port that will serve the given handlers. Returns the Listener for the server, the port it's listening on, or an error if something went wrong while trying to start the listener. The provided context is used when establishing the network listener. Make sure to call the Close() method on the Listener when you're done!
func RunDummyServerWithHandlersContextE ¶
func RunDummyServerWithHandlersContextE(t testing.TestingT, ctx context.Context, handlers map[string]func(http.ResponseWriter, *http.Request)) (net.Listener, int, error)
RunDummyServerWithHandlersContextE runs a dummy HTTP server on a unique port that will serve the given handlers. Returns the Listener for the server, the port it's listening on, or an error if something went wrong while trying to start the listener. The provided context is used when establishing the network listener. Make sure to call the Close() method on the Listener when you're done!
Types ¶
type GetResponse ¶
GetResponse represents the response from an HTTP GET request.
type HttpDoOptions ¶
type HttpDoOptions struct {
// Context for the HTTP request. If nil, context.Background() is used.
Context context.Context
Body io.Reader
Headers map[string]string
TlsConfig *tls.Config //nolint:staticcheck,revive // preserving existing field name
Method string
Url string //nolint:staticcheck,revive // preserving existing field name
Timeout int
}
HttpDoOptions defines options for HTTP requests using an arbitrary method.
type HttpGetOptions ¶
type HttpGetOptions struct {
// Context for the HTTP request. If nil, context.Background() is used.
Context context.Context
TlsConfig *tls.Config //nolint:staticcheck,revive // preserving existing field name
Url string //nolint:staticcheck,revive // preserving existing field name
Timeout int
}
HttpGetOptions defines options for HTTP GET requests.
type ValidationFunctionFailed ¶
type ValidationFunctionFailed struct {
Url string //nolint:staticcheck // preserving existing field name
Body string
Status int
}
ValidationFunctionFailed is an error that occurs if a validation function fails.
func (ValidationFunctionFailed) Error ¶
func (err ValidationFunctionFailed) Error() string