diff --git a/test/integration/mysql/mysql_test.go b/test/integration/mysql/mysql_test.go index 53516ca..a0353de 100644 --- a/test/integration/mysql/mysql_test.go +++ b/test/integration/mysql/mysql_test.go @@ -19,7 +19,7 @@ import ( "time" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" - "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration" + test "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration" "github.com/stretchr/testify/assert" ) diff --git a/test/integration/simple_example/simple_example_test.go b/test/integration/simple_example/simple_example_test.go index 81fdb7d..99d924b 100644 --- a/test/integration/simple_example/simple_example_test.go +++ b/test/integration/simple_example/simple_example_test.go @@ -22,7 +22,7 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" - "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration" + test "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration" "github.com/stretchr/testify/assert" ) diff --git a/test/integration/test_deployment_url.go b/test/integration/test_deployment_url.go index 39640ba..1053b28 100644 --- a/test/integration/test_deployment_url.go +++ b/test/integration/test_deployment_url.go @@ -15,38 +15,22 @@ package test import ( - "fmt" - "io/ioutil" "net/http" "testing" "time" + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" "github.com/stretchr/testify/assert" ) func TestDeploymentUrl(t *testing.T, assert *assert.Assertions, url string) error { - for attemptNum := 1; attemptNum <= 60; attemptNum++ { - - response, err := http.Get(url) - if err != nil { - t.Logf("Deployment URL HTTP request error: %s\n", err) - - } else if 200 <= response.StatusCode && response.StatusCode <= 299 { // Got some 200 response - responseBody, err := ioutil.ReadAll(response.Body) - if err != nil { - return err - } - responseBodyString := string(responseBody) - assert.Containsf(responseBodyString, "Todo", "Couldn't find text 'Todo' in deployment's response") - return nil - - } else { // Got a non-200 response - t.Logf("Deployment URL responded with status code: %d.\n", response.StatusCode) - } - - // Wait before retrying - time.Sleep(4 * time.Second) + httpRequest, err := http.NewRequest("GET", url, nil) + if err != nil { + return err } - - return fmt.Errorf("Deployment URL %s failed to respond with a 200 status code even after a few minutes.", url) + maxRetries := 60 + waitBetweenRetries := 4 * time.Second + assertHttp := utils.NewAssertHTTP(utils.WithHTTPRequestRetries(maxRetries, waitBetweenRetries)) + assertHttp.AssertResponseWithRetry(t, httpRequest, http.StatusOK, "Todo") + return nil }