Skip to content

Commit

Permalink
chore: Test deployment URLs in integration tests (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
NimJay authored Oct 29, 2024
1 parent ab8330c commit 66b37b9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/integration/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/terraform-google-modules/three-tier-app/test/integration
module github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration

go 1.22

Expand Down
4 changes: 4 additions & 0 deletions test/integration/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
test "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration"
"github.com/stretchr/testify/assert"
)

Expand All @@ -36,6 +37,9 @@ func TestMysql(t *testing.T) {
// DefaultVerify asserts no resource changes exist after apply.
// It helps ensure that a second "terraform apply" wouldn't result in resource deletions/replacements.
blueprintTest.DefaultVerify(assert)

deploymentUrl := blueprintTest.GetStringOutput("endpoint")
test.TestDeploymentUrl(t, deploymentUrl)
})

blueprintTest.Test()
Expand Down
4 changes: 4 additions & 0 deletions test/integration/simple_example/simple_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +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"
test "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -130,6 +131,9 @@ func TestSimpleExample(t *testing.T) {
assert.Equal("ENABLED", match.Get("state").String(), "%s service should be enabled", tc.service)
})
}

deploymentUrl := example.GetStringOutput("endpoint")
test.TestDeploymentUrl(t, deploymentUrl)
})
example.Test()
}
35 changes: 35 additions & 0 deletions test/integration/test_deployment_url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

import (
"net/http"
"testing"
"time"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
)

func TestDeploymentUrl(t *testing.T, url string) error {
httpRequest, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
maxRetries := 60
waitBetweenRetries := 4 * time.Second
assertHttp := utils.NewAssertHTTP(utils.WithHTTPRequestRetries(maxRetries, waitBetweenRetries))
assertHttp.AssertResponseWithRetry(t, httpRequest, http.StatusOK, "<title>Todo</title>")
return nil
}

0 comments on commit 66b37b9

Please sign in to comment.