Skip to content

Commit 50e13cf

Browse files
committed
chore(CI): migrate tests to CFT
1 parent 0ebdfda commit 50e13cf

File tree

8 files changed

+99
-208
lines changed

8 files changed

+99
-208
lines changed

.kitchen.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ suites:
159159
systems:
160160
- name: stub_domains_upstream_nameservers
161161
backend: local
162-
- name: "workload_identity"
163-
transport:
164-
root_module_directory: test/fixtures/workload_identity
165-
verifier:
166-
systems:
167-
- name: gcloud
168-
backend: local
169-
controls:
170-
- gcloud
171-
- name: gcp
172-
backend: gcp
173-
controls:
174-
- gcp
175162
- name: "workload_metadata_config"
176163
transport:
177164
root_module_directory: test/fixtures/workload_metadata_config
@@ -219,13 +206,6 @@ suites:
219206
systems:
220207
- name: sandbox_enabled
221208
backend: local
222-
- name: "safer_cluster_iap_bastion"
223-
transport:
224-
root_module_directory: test/fixtures/safer_cluster_iap_bastion
225-
verifier:
226-
systems:
227-
- name: safer_cluster_iap_bastion
228-
backend: local
229209
- name: "simple_zonal_with_asm"
230210
transport:
231211
root_module_directory: test/fixtures/simple_zonal_with_asm

build/int.cloudbuild.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,32 +404,32 @@ steps:
404404
waitFor:
405405
- create-all
406406
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
407-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge workload-identity-local']
407+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage apply --verbose']
408408
- id: verify workload-identity-local
409409
waitFor:
410410
- converge workload-identity-local
411411
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
412-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify workload-identity-local']
412+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage verify --verbose']
413413
- id: destroy workload-identity-local
414414
waitFor:
415415
- verify workload-identity-local
416416
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
417-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy workload-identity-local']
417+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage destroy --verbose']
418418
- id: converge safer-cluster-iap-bastion-local
419419
waitFor:
420420
- create-all
421421
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
422-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge safer-cluster-iap-bastion-local']
422+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage apply --verbose']
423423
- id: verify safer-cluster-iap-bastion-local
424424
waitFor:
425425
- converge safer-cluster-iap-bastion-local
426426
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
427-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify safer-cluster-iap-bastion-local']
427+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage verify --verbose']
428428
- id: destroy safer-cluster-iap-bastion-local
429429
waitFor:
430430
- verify safer-cluster-iap-bastion-local
431431
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
432-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy safer-cluster-iap-bastion-local']
432+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage teardown --verbose']
433433
- id: init simple-zonal-with-asm-local
434434
waitFor:
435435
- create-all

test/integration/safer_cluster_iap_bastion/controls/e2e.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/integration/safer_cluster_iap_bastion/inspec.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2022-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+
package safer_cluster_iap_bastion
15+
16+
import (
17+
"strings"
18+
"testing"
19+
"time"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
25+
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils"
26+
)
27+
28+
func TestSaferClusterIapBastion(t *testing.T) {
29+
bpt := tft.NewTFBlueprintTest(t,
30+
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute),
31+
)
32+
33+
bpt.DefineVerify(func(assert *assert.Assertions) {
34+
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token
35+
// bpt.DefaultVerify(assert)
36+
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources
37+
38+
test_command, _ := strings.CutPrefix(bpt.GetStringOutput("test_command"), "gcloud ")
39+
cluster_version := bpt.GetStringOutput("cluster_version")
40+
41+
op := gcloud.Runf(t, test_command)
42+
43+
assert.Equal(cluster_version, op.Get("gitVersion").String(), "SSH into VM and verify connectivity to GKE")
44+
})
45+
46+
bpt.Test()
47+
}

test/integration/workload_identity/controls/gcloud.rb

Lines changed: 0 additions & 80 deletions
This file was deleted.

test/integration/workload_identity/inspec.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2022-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+
package workload_identity
15+
16+
import (
17+
"fmt"
18+
"testing"
19+
"time"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
25+
)
26+
27+
func TestWorkloadIdentity(t *testing.T) {
28+
bpt := tft.NewTFBlueprintTest(t,
29+
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute),
30+
)
31+
32+
bpt.DefineVerify(func(assert *assert.Assertions) {
33+
bpt.DefaultVerify(assert)
34+
35+
projectId := bpt.GetStringOutput("project_id")
36+
location := bpt.GetStringOutput("location")
37+
clusterName := bpt.GetStringOutput("cluster_name")
38+
39+
op := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
40+
assert.Equal("RUNNING", op.Get("status").String(), "Cluster is Running")
41+
assert.Equal("GKE_METADATA", op.Get("nodePools.0.config.workloadMetadataConfig.mode").String(), "workload metada config is secure")
42+
assert.Equal(fmt.Sprintf("%s.svc.id.goog", projectId), op.Get("workloadIdentityConfig.workloadPool").String(), "workload identity config has correct project")
43+
})
44+
45+
bpt.Test()
46+
}

0 commit comments

Comments
 (0)