diff --git a/modules/http-helper/http_helper.go b/modules/http-helper/http_helper.go index 444087a3f..7d9e1361a 100644 --- a/modules/http-helper/http_helper.go +++ b/modules/http-helper/http_helper.go @@ -16,10 +16,31 @@ import ( "github.com/gruntwork-io/terratest/modules/testing" ) +type HttpGetOptions struct { + Url string + TlsConfig *tls.Config + Timeout int +} + +type HttpDoOptions struct { + Method string + Url string + Body io.Reader + Headers map[string]string + TlsConfig *tls.Config + Timeout int +} + // 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 HttpGet(t testing.TestingT, url string, tlsConfig *tls.Config) (int, string) { - statusCode, body, err := HttpGetE(t, url, tlsConfig) + return HttpGetWithOptions(t, HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10}) +} + +// 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 HttpGetWithOptions(t testing.TestingT, options HttpGetOptions) (int, string) { + statusCode, body, err := HttpGetWithOptionsE(t, options) if err != nil { t.Fatal(err) } @@ -29,20 +50,26 @@ func HttpGet(t testing.TestingT, url string, tlsConfig *tls.Config) (int, string // 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 HttpGetE(t testing.TestingT, url string, tlsConfig *tls.Config) (int, string, error) { - logger.Logf(t, "Making an HTTP GET call to URL %s", url) + return HttpGetWithOptionsE(t, HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10}) +} + +// HttpGetWithOptionsE 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 HttpGetWithOptionsE(t testing.TestingT, options HttpGetOptions) (int, string, error) { + logger.Logf(t, "Making an HTTP GET call to URL %s", options.Url) // Set HTTP client transport config tr := http.DefaultTransport.(*http.Transport).Clone() - tr.TLSClientConfig = tlsConfig + tr.TLSClientConfig = options.TlsConfig client := http.Client{ // By default, Go does not impose a timeout, so an HTTP connection attempt can hang for a LONG time. - Timeout: 10 * time.Second, + Timeout: time.Duration(options.Timeout) * time.Second, // Include the previously created transport config Transport: tr, } - resp, err := client.Get(url) + resp, err := client.Get(options.Url) if err != nil { return -1, "", err } @@ -60,7 +87,14 @@ func HttpGetE(t testing.TestingT, url string, tlsConfig *tls.Config) (int, strin // 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 HttpGetWithValidation(t testing.TestingT, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string) { - err := HttpGetWithValidationE(t, url, tlsConfig, expectedStatusCode, expectedBody) + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + HttpGetWithValidationWithOptions(t, options, expectedStatusCode, expectedBody) +} + +// 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 HttpGetWithValidationWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, expectedBody string) { + err := HttpGetWithValidationWithOptionsE(t, options, expectedStatusCode, expectedBody) if err != nil { t.Fatal(err) } @@ -69,14 +103,26 @@ func HttpGetWithValidation(t testing.TestingT, url string, tlsConfig *tls.Config // 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 HttpGetWithValidationE(t testing.TestingT, url string, tlsConfig *tls.Config, expectedStatusCode int, expectedBody string) error { - return HttpGetWithCustomValidationE(t, url, tlsConfig, func(statusCode int, body string) bool { + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + return HttpGetWithValidationWithOptionsE(t, options, expectedStatusCode, expectedBody) +} + +// 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 HttpGetWithValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatusCode int, expectedBody string) error { + return HttpGetWithCustomValidationWithOptionsE(t, options, func(statusCode int, body string) bool { return statusCode == expectedStatusCode && body == expectedBody }) } // HttpGetWithCustomValidation performs an HTTP GET on the given URL and validate the returned status code and body using the given function. func HttpGetWithCustomValidation(t testing.TestingT, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool) { - err := HttpGetWithCustomValidationE(t, url, tlsConfig, validateResponse) + HttpGetWithCustomValidationWithOptions(t, HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10}, validateResponse) +} + +// HttpGetWithCustomValidationWithOptions performs an HTTP GET on the given URL and validate the returned status code and body using the given function. +func HttpGetWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, validateResponse func(int, string) bool) { + err := HttpGetWithCustomValidationWithOptionsE(t, options, validateResponse) if err != nil { t.Fatal(err) } @@ -84,14 +130,19 @@ func HttpGetWithCustomValidation(t testing.TestingT, url string, tlsConfig *tls. // HttpGetWithCustomValidationE performs an HTTP GET on the given URL and validate the returned status code and body using the given function. func HttpGetWithCustomValidationE(t testing.TestingT, url string, tlsConfig *tls.Config, validateResponse func(int, string) bool) error { - statusCode, body, err := HttpGetE(t, url, tlsConfig) + return HttpGetWithCustomValidationWithOptionsE(t, HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10}, validateResponse) +} + +// HttpGetWithCustomValidationWithOptionsE performs an HTTP GET on the given URL and validate the returned status code and body using the given function. +func HttpGetWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, validateResponse func(int, string) bool) error { + statusCode, body, err := HttpGetWithOptionsE(t, options) if err != nil { return err } if !validateResponse(statusCode, body) { - return ValidationFunctionFailed{Url: url, Status: statusCode, Body: body} + return ValidationFunctionFailed{Url: options.Url, Status: statusCode, Body: body} } return nil @@ -100,7 +151,14 @@ func HttpGetWithCustomValidationE(t testing.TestingT, url string, tlsConfig *tls // 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 HttpGetWithRetry(t testing.TestingT, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) { - err := HttpGetWithRetryE(t, url, tlsConfig, expectedStatus, expectedBody, retries, sleepBetweenRetries) + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + HttpGetWithRetryWithOptions(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) +} + +// 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 HttpGetWithRetryWithOptions(t testing.TestingT, options HttpGetOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) { + err := HttpGetWithRetryWithOptionsE(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) if err != nil { t.Fatal(err) } @@ -109,8 +167,15 @@ func HttpGetWithRetry(t testing.TestingT, url string, tlsConfig *tls.Config, exp // 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 HttpGetWithRetryE(t testing.TestingT, url string, tlsConfig *tls.Config, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) error { - _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP GET to URL %s", url), retries, sleepBetweenRetries, func() (string, error) { - return "", HttpGetWithValidationE(t, url, tlsConfig, expectedStatus, expectedBody) + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + return HttpGetWithRetryWithOptionsE(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) +} + +// 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 HttpGetWithRetryWithOptionsE(t testing.TestingT, options HttpGetOptions, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration) error { + _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP GET to URL %s", options.Url), retries, sleepBetweenRetries, func() (string, error) { + return "", HttpGetWithValidationWithOptionsE(t, options, expectedStatus, expectedBody) }) return err @@ -119,7 +184,14 @@ func HttpGetWithRetryE(t testing.TestingT, url string, tlsConfig *tls.Config, ex // HttpGetWithRetryWithCustomValidation repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries // has been exceeded. func HttpGetWithRetryWithCustomValidation(t testing.TestingT, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) { - err := HttpGetWithRetryWithCustomValidationE(t, url, tlsConfig, retries, sleepBetweenRetries, validateResponse) + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + HttpGetWithRetryWithCustomValidationWithOptions(t, options, retries, sleepBetweenRetries, validateResponse) +} + +// HttpGetWithRetryWithCustomValidationWithOptions repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries +// has been exceeded. +func HttpGetWithRetryWithCustomValidationWithOptions(t testing.TestingT, options HttpGetOptions, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) { + err := HttpGetWithRetryWithCustomValidationWithOptionsE(t, options, retries, sleepBetweenRetries, validateResponse) if err != nil { t.Fatal(err) } @@ -128,8 +200,15 @@ func HttpGetWithRetryWithCustomValidation(t testing.TestingT, url string, tlsCon // HttpGetWithRetryWithCustomValidationE repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries // has been exceeded. func HttpGetWithRetryWithCustomValidationE(t testing.TestingT, url string, tlsConfig *tls.Config, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) error { - _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP GET to URL %s", url), retries, sleepBetweenRetries, func() (string, error) { - return "", HttpGetWithCustomValidationE(t, url, tlsConfig, validateResponse) + options := HttpGetOptions{Url: url, TlsConfig: tlsConfig, Timeout: 10} + return HttpGetWithRetryWithCustomValidationWithOptionsE(t, options, retries, sleepBetweenRetries, validateResponse) +} + +// HttpGetWithRetryWithCustomValidationWithOptionsE repeatedly performs an HTTP GET on the given URL until the given validation function returns true or max retries +// has been exceeded. +func HttpGetWithRetryWithCustomValidationWithOptionsE(t testing.TestingT, options HttpGetOptions, retries int, sleepBetweenRetries time.Duration, validateResponse func(int, string) bool) error { + _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP GET to URL %s", options.Url), retries, sleepBetweenRetries, func() (string, error) { + return "", HttpGetWithCustomValidationWithOptionsE(t, options, validateResponse) }) return err @@ -141,7 +220,22 @@ func HTTPDo( t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, tlsConfig *tls.Config, ) (int, string) { - statusCode, respBody, err := HTTPDoE(t, method, url, body, headers, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + return HTTPDoWithOptions(t, options) +} + +// 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 HTTPDoWithOptions( + t testing.TestingT, options HttpDoOptions, +) (int, string) { + statusCode, respBody, err := HTTPDoWithOptionsE(t, options) if err != nil { t.Fatal(err) } @@ -153,19 +247,33 @@ func HTTPDoE( t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, tlsConfig *tls.Config, ) (int, string, error) { - logger.Logf(t, "Making an HTTP %s call to URL %s", method, url) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + Timeout: 10, + TlsConfig: tlsConfig} + return HTTPDoWithOptionsE(t, options) +} + +// HTTPDoWithOptionsE performs the given HTTP method on the given URL and return the HTTP status code, body, and any error. +func HTTPDoWithOptionsE( + t testing.TestingT, options HttpDoOptions, +) (int, string, error) { + logger.Logf(t, "Making an HTTP %s call to URL %s", options.Method, options.Url) tr := &http.Transport{ - TLSClientConfig: tlsConfig, + TLSClientConfig: options.TlsConfig, } client := http.Client{ // By default, Go does not impose a timeout, so an HTTP connection attempt can hang for a LONG time. - Timeout: 10 * time.Second, + Timeout: time.Duration(options.Timeout) * time.Second, Transport: tr, } - req := newRequest(method, url, body, headers) + req := newRequest(options.Method, options.Url, options.Body, options.Headers) resp, err := client.Do(req) if err != nil { return -1, "", err @@ -189,8 +297,24 @@ func HTTPDoWithRetry( body []byte, headers map[string]string, expectedStatus int, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) string { - out, err := HTTPDoWithRetryE(t, method, url, body, - headers, expectedStatus, retries, sleepBetweenRetries, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: bytes.NewReader(body), + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + return HTTPDoWithRetryWithOptions(t, options, expectedStatus, retries, sleepBetweenRetries) +} + +// 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 HTTPDoWithRetryWithOptions( + t testing.TestingT, options HttpDoOptions, expectedStatus int, + retries int, sleepBetweenRetries time.Duration, +) string { + out, err := HTTPDoWithRetryWithOptionsE(t, options, expectedStatus, retries, sleepBetweenRetries) if err != nil { t.Fatal(err) } @@ -205,17 +329,44 @@ func HTTPDoWithRetryE( body []byte, headers map[string]string, expectedStatus int, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) (string, error) { + options := HttpDoOptions{ + Method: method, + Url: url, + Body: bytes.NewReader(body), + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + return HTTPDoWithRetryWithOptionsE(t, options, expectedStatus, retries, sleepBetweenRetries) +} + +// 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 HTTPDoWithRetryWithOptionsE( + t testing.TestingT, options HttpDoOptions, expectedStatus int, + retries int, sleepBetweenRetries time.Duration, +) (string, error) { + // The request body is closed after a request is complete. + // Extract the underlying data and cache it so we can reuse for retried requests + data, err := io.ReadAll(options.Body) + if err != nil { + return "", err + } + + options.Body = nil + out, err := retry.DoWithRetryE( - t, fmt.Sprintf("HTTP %s to URL %s", method, url), retries, + t, fmt.Sprintf("HTTP %s to URL %s", options.Method, options.Url), retries, sleepBetweenRetries, func() (string, error) { - bodyReader := bytes.NewReader(body) - statusCode, out, err := HTTPDoE(t, method, url, bodyReader, headers, tlsConfig) + options.Body = bytes.NewReader(data) + statusCode, out, err := HTTPDoWithOptionsE(t, options) if err != nil { return "", err } logger.Logf(t, "output: %v", out) if statusCode != expectedStatus { - return "", ValidationFunctionFailed{Url: url, Status: statusCode} + return "", ValidationFunctionFailed{Url: options.Url, Status: statusCode} } return out, nil }) @@ -230,7 +381,24 @@ func HTTPDoWithValidationRetry( body []byte, headers map[string]string, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) { - err := HTTPDoWithValidationRetryE(t, method, url, body, headers, expectedStatus, expectedBody, retries, sleepBetweenRetries, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: bytes.NewReader(body), + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + HTTPDoWithValidationRetryWithOptions(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) +} + +// 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 HTTPDoWithValidationRetryWithOptions( + t testing.TestingT, options HttpDoOptions, expectedStatus int, + expectedBody string, retries int, sleepBetweenRetries time.Duration, +) { + err := HTTPDoWithValidationRetryWithOptionsE(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) if err != nil { t.Fatal(err) } @@ -243,10 +411,26 @@ func HTTPDoWithValidationRetryE( body []byte, headers map[string]string, expectedStatus int, expectedBody string, retries int, sleepBetweenRetries time.Duration, tlsConfig *tls.Config, ) error { - _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP %s to URL %s", method, url), retries, + options := HttpDoOptions{ + Method: method, + Url: url, + Body: bytes.NewReader(body), + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + return HTTPDoWithValidationRetryWithOptionsE(t, options, expectedStatus, expectedBody, retries, sleepBetweenRetries) +} + +// 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 HTTPDoWithValidationRetryWithOptionsE( + t testing.TestingT, options HttpDoOptions, expectedStatus int, + expectedBody string, retries int, sleepBetweenRetries time.Duration, +) error { + _, err := retry.DoWithRetryE(t, fmt.Sprintf("HTTP %s to URL %s", options.Method, options.Url), retries, sleepBetweenRetries, func() (string, error) { - bodyReader := bytes.NewReader(body) - return "", HTTPDoWithValidationE(t, method, url, bodyReader, headers, expectedStatus, expectedBody, tlsConfig) + return "", HTTPDoWithValidationWithOptionsE(t, options, expectedStatus, expectedBody) }) return err @@ -255,7 +439,21 @@ func HTTPDoWithValidationRetryE( // 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 HTTPDoWithValidation(t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string, tlsConfig *tls.Config) { - err := HTTPDoWithValidationE(t, method, url, body, headers, expectedStatusCode, expectedBody, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + HTTPDoWithValidationWithOptions(t, options, expectedStatusCode, expectedBody) +} + +// 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 HTTPDoWithValidationWithOptions(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, expectedBody string) { + err := HTTPDoWithValidationWithOptionsE(t, options, expectedStatusCode, expectedBody) if err != nil { t.Fatal(err) } @@ -264,15 +462,43 @@ func HTTPDoWithValidation(t testing.TestingT, method string, url string, body io // 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 HTTPDoWithValidationE(t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, expectedStatusCode int, expectedBody string, tlsConfig *tls.Config) error { - return HTTPDoWithCustomValidationE(t, method, url, body, headers, func(statusCode int, body string) bool { + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + return HTTPDoWithValidationWithOptionsE(t, options, expectedStatusCode, expectedBody) +} + +// 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 HTTPDoWithValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, expectedStatusCode int, expectedBody string) error { + return HTTPDoWithCustomValidationWithOptionsE(t, options, func(statusCode int, body string) bool { return statusCode == expectedStatusCode && body == expectedBody - }, tlsConfig) + }) } // HTTPDoWithCustomValidation performs the given HTTP method on the given URL and validate the returned status code and // body using the given function. func HTTPDoWithCustomValidation(t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool, tlsConfig *tls.Config) { - err := HTTPDoWithCustomValidationE(t, method, url, body, headers, validateResponse, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + HTTPDoWithCustomValidationWithOptions(t, options, validateResponse) +} + +// HTTPDoWithCustomValidationWithOptions performs the given HTTP method on the given URL and validate the returned status code and +// body using the given function. +func HTTPDoWithCustomValidationWithOptions(t testing.TestingT, options HttpDoOptions, validateResponse func(int, string) bool) { + err := HTTPDoWithCustomValidationWithOptionsE(t, options, validateResponse) if err != nil { t.Fatal(err) } @@ -281,14 +507,28 @@ func HTTPDoWithCustomValidation(t testing.TestingT, method string, url string, b // HTTPDoWithCustomValidationE performs the given HTTP method on the given URL and validate the returned status code and // body using the given function. func HTTPDoWithCustomValidationE(t testing.TestingT, method string, url string, body io.Reader, headers map[string]string, validateResponse func(int, string) bool, tlsConfig *tls.Config) error { - statusCode, respBody, err := HTTPDoE(t, method, url, body, headers, tlsConfig) + options := HttpDoOptions{ + Method: method, + Url: url, + Body: body, + Headers: headers, + TlsConfig: tlsConfig, + Timeout: 10} + + return HTTPDoWithCustomValidationWithOptionsE(t, options, validateResponse) +} + +// HTTPDoWithCustomValidationWithOptionsE performs the given HTTP method on the given URL and validate the returned status code and +// body using the given function. +func HTTPDoWithCustomValidationWithOptionsE(t testing.TestingT, options HttpDoOptions, validateResponse func(int, string) bool) error { + statusCode, respBody, err := HTTPDoWithOptionsE(t, options) if err != nil { return err } if !validateResponse(statusCode, respBody) { - return ValidationFunctionFailed{Url: url, Status: statusCode, Body: respBody} + return ValidationFunctionFailed{Url: options.Url, Status: statusCode, Body: respBody} } return nil