Skip to content

Commit 66fc20e

Browse files
chore: Migrating test Framework for 3 test cases (#1489)
* Migrating Test Framework for 3test cases * Correcting Build File * Correcting Build File * Correcting Build File * Modifying Files based on Recommendations * Correcting JSON path * Modifying the path for networkconfig * Changing Sanitizer Order to remove Service Account * Modifying the peering name assert logic * UnSetting ProjectID to skip ProjectID Sanitiser * Removing Default Verify in Testing due to issue 1478 Co-authored-by: Akshay Bathija <[email protected]>
1 parent 363c4b5 commit 66fc20e

File tree

24 files changed

+2358
-710
lines changed

24 files changed

+2358
-710
lines changed

.kitchen.yml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ platforms:
2929
- name: local
3030

3131
suites:
32-
- name: "disable_client_cert"
33-
driver:
34-
root_module_directory: test/fixtures/disable_client_cert
35-
verifier:
36-
systems:
37-
- name: disable_client_cert
38-
backend: local
39-
controls:
40-
- gcloud
4132
- name: "shared_vpc"
4233
driver:
4334
root_module_directory: test/fixtures/shared_vpc
@@ -65,23 +56,6 @@ suites:
6556
systems:
6657
- name: simple_regional
6758
backend: local
68-
- name: "private_zonal_with_networking"
69-
driver:
70-
root_module_directory: test/fixtures/private_zonal_with_networking
71-
verifier:
72-
systems:
73-
- name: private_zonal_with_networking
74-
backend: local
75-
controls:
76-
- gcloud
77-
- name: private_zonal_with_networking
78-
backend: local
79-
controls:
80-
- subnet
81-
- name: network
82-
backend: gcp
83-
controls:
84-
- network
8559
- name: "simple_regional_with_networking"
8660
driver:
8761
root_module_directory: test/fixtures/simple_regional_with_networking
@@ -188,19 +162,6 @@ suites:
188162
systems:
189163
- name: workload_metadata_config
190164
backend: local
191-
- name: "beta_cluster"
192-
driver:
193-
root_module_directory: test/fixtures/beta_cluster
194-
verifier:
195-
systems:
196-
- name: gcloud
197-
backend: local
198-
controls:
199-
- gcloud
200-
- name: gcp
201-
backend: gcp
202-
controls:
203-
- gcp
204165
- name: "simple_windows_node_pool"
205166
driver:
206167
root_module_directory: test/fixtures/simple_windows_node_pool

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
SHELL := /usr/bin/env bash
2020

2121
# Pin to 1.3.9 per https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/issues/1208
22-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.3.9
22+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.8
2323
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2424
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2525
DOCKER_BIN ?= docker

build/int.cloudbuild.yaml

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@ steps:
2626
- prepare
2727
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
2828
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
29-
- id: converge disable-client-cert-local
29+
- id: init disable-client-cert
3030
waitFor:
31-
- create all
31+
- prepare
3232
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
33-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge disable-client-cert-local']
34-
- id: verify disable-client-cert-local
33+
args: ['/bin/bash', '-c', 'cft test run TestDisableClientCert --stage init --verbose --test-dir test/integration']
34+
- id: apply disable-client-cert
3535
waitFor:
36-
- converge disable-client-cert-local
36+
- init disable-client-cert
3737
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
38-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify disable-client-cert-local']
39-
- id: destroy disable-client-cert-local
38+
args: ['/bin/bash', '-c', 'cft test run TestDisableClientCert --stage apply --verbose --test-dir test/integration']
39+
- id: verify disable-client-cert
4040
waitFor:
41-
- verify disable-client-cert-local
41+
- apply disable-client-cert
4242
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
43-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy disable-client-cert-local']
43+
args: ['/bin/bash', '-c', 'cft test run TestDisableClientCert --stage verify --verbose --test-dir test/integration']
44+
- id: teardown disable-client-cert
45+
waitFor:
46+
- verify disable-client-cert
47+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
48+
args: ['/bin/bash', '-c', 'cft test run TestDisableClientCert --stage teardown --verbose --test-dir test/integration']
4449
- id: converge shared-vpc-local
4550
waitFor:
4651
- create all
@@ -222,21 +227,26 @@ steps:
222227
- verify workload-metadata-config-local
223228
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
224229
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy workload-metadata-config-local']
225-
- id: converge beta-cluster-local
230+
- id: init beta-cluster
226231
waitFor:
227-
- create all
232+
- prepare
233+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
234+
args: ['/bin/bash', '-c', 'cft test run TestBetaCluster --stage init --verbose --test-dir test/integration']
235+
- id: apply beta-cluster
236+
waitFor:
237+
- init beta-cluster
228238
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
229-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge beta-cluster-local']
230-
- id: verify beta-cluster-local
239+
args: ['/bin/bash', '-c', 'cft test run TestBetaCluster --stage apply --verbose --test-dir test/integration']
240+
- id: verify beta-cluster
231241
waitFor:
232-
- converge beta-cluster-local
242+
- apply beta-cluster
233243
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
234-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify beta-cluster-local']
235-
- id: destroy beta-cluster-local
244+
args: ['/bin/bash', '-c', 'cft test run TestBetaCluster --stage verify --verbose --test-dir test/integration']
245+
- id: teardown beta-cluster
236246
waitFor:
237-
- verify beta-cluster-local
247+
- verify beta-cluster
238248
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
239-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
249+
args: ['/bin/bash', '-c', 'cft test run TestBetaCluster --stage teardown --verbose --test-dir test/integration']
240250
- id: converge simple-windows-node-pool-local
241251
waitFor:
242252
- create all
@@ -372,11 +382,34 @@ steps:
372382
- verify simple-autopilot-public-local
373383
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
374384
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-autopilot-public-local']
385+
- id: init private-zonal-with-networking
386+
waitFor:
387+
- prepare
388+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
389+
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage init --verbose --test-dir test/integration']
390+
- id: apply private-zonal-with-networking
391+
waitFor:
392+
- init private-zonal-with-networking
393+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
394+
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage apply --verbose --test-dir test/integration']
395+
- id: verify private-zonal-with-networking
396+
waitFor:
397+
- apply private-zonal-with-networking
398+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
399+
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage verify --verbose --test-dir test/integration']
400+
- id: teardown private-zonal-with-networking
401+
waitFor:
402+
- verify private-zonal-with-networking
403+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
404+
args: ['/bin/bash', '-c', 'cft test run TestPrivateZonalWithNetworking --stage teardown --verbose --test-dir test/integration']
405+
406+
407+
375408
tags:
376409
- 'ci'
377410
- 'integration'
378411
substitutions:
379412
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
380-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.5'
413+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.8'
381414
options:
382415
machineType: 'N1_HIGHCPU_8'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tags:
2222
- 'lint'
2323
substitutions:
2424
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
25-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.5'
25+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.8'
2626
options:
2727
machineType: 'N1_HIGHCPU_8'
2828
env:

test/fixtures/beta_cluster/network.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ resource "google_compute_network" "main" {
2727
}
2828

2929
resource "google_compute_subnetwork" "main" {
30-
name = "cft-gke-test-${random_string.suffix.result}"
31-
ip_cidr_range = "10.0.0.0/17"
32-
region = var.region
33-
network = google_compute_network.main.self_link
34-
project = local.project_id
30+
name = "cft-gke-test-${random_string.suffix.result}"
31+
ip_cidr_range = "10.0.0.0/17"
32+
region = var.region
33+
network = google_compute_network.main.self_link
34+
project = local.project_id
35+
private_ip_google_access = true
3536

3637
secondary_ip_range {
3738
range_name = "cft-gke-test-pods-${random_string.suffix.result}"

test/fixtures/beta_cluster/outputs.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@ output "kubernetes_endpoint" {
6464
value = module.this.kubernetes_endpoint
6565
}
6666

67-
output "client_token" {
68-
sensitive = true
69-
value = base64encode(data.google_client_config.default.access_token)
70-
}
71-
72-
output "ca_certificate" {
73-
description = "The cluster CA certificate"
74-
value = module.this.ca_certificate
75-
sensitive = true
76-
}
77-
7867
output "service_account" {
7968
description = "The service account to default running nodes as if not overridden in `node_pools`."
8069
value = module.this.service_account
@@ -83,7 +72,3 @@ output "service_account" {
8372
output "database_encryption_key_name" {
8473
value = google_kms_crypto_key.db.id
8574
}
86-
87-
output "identity_namespace" {
88-
value = module.this.identity_namespace
89-
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2022 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 beta_cluster
16+
17+
import (
18+
"fmt"
19+
"testing"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
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 TestBetaCluster(t *testing.T) {
29+
gke := tft.NewTFBlueprintTest(t)
30+
31+
gke.DefineVerify(func(assert *assert.Assertions) {
32+
// Commenting Default Verify due to issue 1478 for location Policy
33+
// gke.DefaultVerify(assert) //disables no changes
34+
35+
projectId := gke.GetStringOutput("project_id")
36+
location := gke.GetStringOutput("location")
37+
clusterName := gke.GetStringOutput("cluster_name")
38+
serviceAccount := gke.GetStringOutput("service_account")
39+
gcloud.Runf(t, "config set project %s", projectId)
40+
op := gcloud.Runf(t, "beta container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
41+
// save output as goldenfile
42+
g := golden.NewOrUpdate(t, op.String(),
43+
golden.WithSanitizer(golden.StringSanitizer(serviceAccount, "SERVICE_ACCOUNT")),
44+
golden.WithSanitizer(golden.StringSanitizer(projectId, "PROJECT_ID")),
45+
golden.WithSanitizer(golden.StringSanitizer(clusterName, "CLUSTER_NAME")),
46+
)
47+
// assert json paths against goldenfile data
48+
validateJSONPaths := []string{
49+
"status",
50+
"location",
51+
"locations",
52+
"privateClusterConfig.enablePrivateEndpoint",
53+
"networkConfig.datapathProvider",
54+
"podSecurityPolicyConfig.enabled",
55+
"databaseEncryption.state",
56+
"identityServiceConfig.enabled",
57+
"addonsConfig",
58+
"networkConfig.datapathProvider",
59+
"binaryAuthorization",
60+
"podSecurityPolicyConfig",
61+
"databaseEncryption.state",
62+
"loggingConfig",
63+
"monitoringConfig",
64+
}
65+
for _, pth := range validateJSONPaths {
66+
g.JSONEq(assert, op, pth)
67+
}
68+
for _, np := range op.Get("nodePools").Array() {
69+
npName := np.Get("name").String()
70+
// sanitze current nodepool data
71+
np = g.GetSanitizedJSON(np)
72+
// retrive matching nodepool data from goldenfile
73+
gNp := utils.GetFirstMatchResult(t, g.GetJSON().Get("nodePools").Array(), "name", npName)
74+
switch npName {
75+
case "default-pool":
76+
assert.False(np.Get("initialNodeCount").Exists(), "has no initial node count")
77+
assert.False(np.Get("autoscaling").Exists(), "does not have autoscaling enabled")
78+
case "default-node-pool":
79+
assert.JSONEq(gNp.Get("config").String(), np.Get("config").String())
80+
assert.JSONEq(gNp.Get("autoscaling").String(), np.Get("autoscaling").String())
81+
assert.JSONEq(gNp.Get("management").String(), np.Get("management").String())
82+
}
83+
}
84+
85+
// verify SA
86+
op = gcloud.Runf(t, "iam service-accounts describe %s --project %s", serviceAccount, projectId)
87+
assert.Equal(fmt.Sprintf("Terraform-managed service account for cluster %s", clusterName), op.Get("displayName").String(), "has the correct displayname")
88+
89+
})
90+
gke.Test()
91+
}

0 commit comments

Comments
 (0)