http_helper

package
v0.19.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package http_helper contains helpers to interact with deployed resources through HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContinuouslyCheckUrl added in v0.13.16

func ContinuouslyCheckUrl(
	t *testing.T,
	url string,
	stopChecking <-chan bool,
	sleepBetweenChecks time.Duration,
) (*sync.WaitGroup, <-chan GetResponse)

Continuously check the given URL every 1 second until the stopChecking channel receives a signal to stop. This function will return 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. Note that the channel has a buffer of 1000, after which it will start to drop the send events

func HTTPDo added in v0.18.5

func HTTPDo(
	t *testing.T, method string, url string, body io.Reader,
	headers map[string]string,
) (int, string)

HTTPDo 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 HTTPDoE added in v0.18.5

func HTTPDoE(
	t *testing.T, method string, url string, body io.Reader,
	headers map[string]string,
) (int, string, error)

HTTPDoE performs the given HTTP method on the given URL and return the HTTP status code, body, and any error.

func HTTPDoWithCustomValidation added in v0.18.5

func HTTPDoWithCustomValidation(t *testing.T, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool)

HTTPDoWithCustomValidation performs the given HTTP method on the given URL and validate the returned status code and body using the given function.

func HTTPDoWithCustomValidationE added in v0.18.5

func HTTPDoWithCustomValidationE(t *testing.T, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool) error

HTTPDoWithCustomValidationE performs the given HTTP method on the given URL and validate the returned status code and body using the given function.

func HTTPDoWithRetry added in v0.18.5

func HTTPDoWithRetry(
	t *testing.T, method string, url string,
	body []byte, headers map[string]string, expectedStatus int,
	retries int, sleepBetweenRetries time.Duration,
) string

HTTPDoWithRetry 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 HTTPDoWithRetryE added in v0.18.5

func HTTPDoWithRetryE(
	t *testing.T, method string, url string,
	body []byte, headers map[string]string, expectedStatus int,
	retries int, sleepBetweenRetries time.Duration,
) (string, error)

HTTPDoWithRetryE 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 HTTPDoWithValidation added in v0.18.5

func HTTPDoWithValidation(t *testing.T, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string)

HTTPDoWithValidation 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 HTTPDoWithValidationE added in v0.18.5

func HTTPDoWithValidationE(t *testing.T, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string) error

HTTPDoWithValidationE 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 HTTPDoWithValidationRetry added in v0.18.5

func HTTPDoWithValidationRetry(
	t *testing.T, method string, url string,
	body []byte, headers map[string]string, expectedStatus int,
	expectedBody string, retries int, sleepBetweenRetries time.Duration,
)

HTTPDoWithValidationRetry 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 HTTPDoWithValidationRetryE added in v0.18.5

func HTTPDoWithValidationRetryE(
	t *testing.T, method string, url string,
	body []byte, headers map[string]string, expectedStatus int,
	expectedBody string, retries int, sleepBetweenRetries time.Duration,
) error

HTTPDoWithValidationRetryE 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 HttpGet

func HttpGet(t *testing.T, url string, tlsConfig *tls.Config) (int, string)

HttpGet 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 HttpGetE

func HttpGetE(t *testing.T, url string, tlsConfig *tls.Config) (int, string, error)

HttpGetE performs an HTTP GET, with an optional pointer to a custom TLS configuration, on the given URL and return the HTTP status code, body, and any error.

func HttpGetWithCustomValidation

func HttpGetWithCustomValidation(t *testing.T, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool)

HttpGetWithCustomValidation performs an HTTP GET on the given URL and validate the returned status code and body using the given function.

func HttpGetWithCustomValidationE

func HttpGetWithCustomValidationE(t *testing.T, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool) error

HttpGetWithCustomValidationE performs an HTTP GET on the given URL and validate the returned status code and body using the given function.

func HttpGetWithRetry

func HttpGetWithRetry(t *testing.T, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration)

HttpGetWithRetry 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 HttpGetWithRetryE

func HttpGetWithRetryE(t *testing.T, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) error

HttpGetWithRetryE 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 HttpGetWithRetryWithCustomValidation

func HttpGetWithRetryWithCustomValidation(t *testing.T, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool)

HttpGetWithRetryWithCustomValidation repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded.

func HttpGetWithRetryWithCustomValidationE

func HttpGetWithRetryWithCustomValidationE(t *testing.T, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) error

HttpGetWithRetryWithCustomValidationE repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries has been exceeded.

func HttpGetWithValidation

func HttpGetWithValidation(t *testing.T, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string)

HttpGetWithValidation 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 HttpGetWithValidationE

func HttpGetWithValidationE(t *testing.T, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string) error

HttpGetWithValidationE 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 RunDummyServer

func RunDummyServer(t *testing.T, text string) (net.Listener, int)

RunDummyServer 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. Make sure to call the Close() method on the Listener when you're done!

func RunDummyServerE

func RunDummyServerE(t *testing.T, text string) (net.Listener, int, error)

RunDummyServerE 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. Make sure to call the Close() method on the Listener when you're done!

func RunDummyServerWithHandlers added in v0.18.5

func RunDummyServerWithHandlers(t *testing.T, handlers map[string]func(http.ResponseWriter, *http.Request)) (net.Listener, int)

RunDummyServerWithHandlers runs a dummy HTTP server on a unique port that will serve 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. Make sure to call the Close() method on the Listener when you're done!

func RunDummyServerWithHandlersE added in v0.18.5

func RunDummyServerWithHandlersE(t *testing.T, handlers map[string]func(http.ResponseWriter, *http.Request)) (net.Listener, int, error)

RunDummyServerWithHandlersE runs a dummy HTTP server on a unique port that will server 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. Make sure to call the Close() method on the Listener when you're done!

Types

type GetResponse added in v0.13.16

type GetResponse struct {
	StatusCode int
	Body       string
}

type ValidationFunctionFailed

type ValidationFunctionFailed struct {
	Url    string
	Status int
	Body   string
}

ValidationFunctionFailed is an error that occurs if a validation function fails.

func (ValidationFunctionFailed) Error

func (err ValidationFunctionFailed) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL