Skip to content

Commit 66b37b9

Browse files
authored
chore: Test deployment URLs in integration tests (#155)
1 parent ab8330c commit 66b37b9

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

test/integration/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/terraform-google-modules/three-tier-app/test/integration
1+
module github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration
22

33
go 1.22
44

test/integration/mysql/mysql_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

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

@@ -36,6 +37,9 @@ func TestMysql(t *testing.T) {
3637
// DefaultVerify asserts no resource changes exist after apply.
3738
// It helps ensure that a second "terraform apply" wouldn't result in resource deletions/replacements.
3839
blueprintTest.DefaultVerify(assert)
40+
41+
deploymentUrl := blueprintTest.GetStringOutput("endpoint")
42+
test.TestDeploymentUrl(t, deploymentUrl)
3943
})
4044

4145
blueprintTest.Test()

test/integration/simple_example/simple_example_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
2323
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
2424
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
25+
test "github.com/GoogleCloudPlatform/terraform-google-three-tier-web-app/test/integration"
2526
"github.com/stretchr/testify/assert"
2627
)
2728

@@ -130,6 +131,9 @@ func TestSimpleExample(t *testing.T) {
130131
assert.Equal("ENABLED", match.Get("state").String(), "%s service should be enabled", tc.service)
131132
})
132133
}
134+
135+
deploymentUrl := example.GetStringOutput("endpoint")
136+
test.TestDeploymentUrl(t, deploymentUrl)
133137
})
134138
example.Test()
135139
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package test
16+
17+
import (
18+
"net/http"
19+
"testing"
20+
"time"
21+
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
23+
)
24+
25+
func TestDeploymentUrl(t *testing.T, url string) error {
26+
httpRequest, err := http.NewRequest("GET", url, nil)
27+
if err != nil {
28+
return err
29+
}
30+
maxRetries := 60
31+
waitBetweenRetries := 4 * time.Second
32+
assertHttp := utils.NewAssertHTTP(utils.WithHTTPRequestRetries(maxRetries, waitBetweenRetries))
33+
assertHttp.AssertResponseWithRetry(t, httpRequest, http.StatusOK, "<title>Todo</title>")
34+
return nil
35+
}

0 commit comments

Comments
 (0)