Skip to content

Commit 6971b36

Browse files
committed
feat: added test
1 parent 3fd5310 commit 6971b36

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

build/int.cloudbuild.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ steps:
127127
- verify lb-http-separate-frontend-and-backend
128128
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
129129
args: ['/bin/bash', '-c', 'cft test run TestSeparateFrontendAndBackend --stage teardown --verbose']
130+
# Internal cross regional http load balancer with cloud-run
131+
- id: apply internal-lb-http
132+
waitFor:
133+
- init-all
134+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
135+
args: ['/bin/bash', '-c', 'cft test run TestInternalLbCloudRun --stage apply --verbose']
136+
- id: verify internal-lb-http
137+
waitFor:
138+
- apply internal-lb-http
139+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
140+
args: ['/bin/bash', '-c', 'sleep 360 && cft test run TestInternalLbCloudRun --stage verify --verbose']
141+
- id: teardown internal-lb-http
142+
waitFor:
143+
- verify internal-lb-http
144+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
145+
args: ['/bin/bash', '-c', 'cft test run TestInternalLbCloudRun --stage teardown --verbose']
130146
tags:
131147
- 'ci'
132148
- 'integration'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "external_cloudrun_uris" {
18+
description = "List of URIs for the frontend Cloud Run services"
19+
value = [module.frontend-service-a.service_uri, module.frontend-service-b.service_uri]
20+
}
21+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 internal_lb_cloud_run
16+
17+
import (
18+
"testing"
19+
"fmt"
20+
21+
"net/http"
22+
23+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
24+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
25+
"github.com/stretchr/testify/assert"
26+
)
27+
28+
func TestInternalLbCloudRun(t *testing.T) {
29+
bpt := tft.NewTFBlueprintTest(t)
30+
31+
bpt.DefineVerify(func(assert *assert.Assertions) {
32+
bpt.DefaultVerify(assert)
33+
34+
cloudRunURIs := bpt.GetStringOutputList("external_cloudrun_uris")
35+
36+
assertHttp := utils.NewAssertHTTP()
37+
38+
for _, uri := range cloudRunURIs {
39+
httpRequest, err := http.NewRequest("GET", uri, nil)
40+
if err != nil {
41+
t.Fatalf("Failed to create HTTP request for %s: %v", uri, err)
42+
}
43+
assertHttp.AssertResponse(t, httpRequest, http.StatusOK)
44+
}
45+
})
46+
47+
bpt.Test()
48+
}

test/setup/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module "project-ci-lb-http" {
3636
"run.googleapis.com",
3737
"iam.googleapis.com",
3838
"certificatemanager.googleapis.com",
39+
"vpcaccess.googleapis.com",
3940
]
4041
}
4142

@@ -61,5 +62,6 @@ module "project-ci-lb-http-1" {
6162
"run.googleapis.com",
6263
"iam.googleapis.com",
6364
"certificatemanager.googleapis.com",
65+
"vpcaccess.googleapis.com",
6466
]
6567
}

0 commit comments

Comments
 (0)