Skip to content

Commit 9ad4082

Browse files
authored
chore(CI): migrate tests to cft (#2234)
1 parent 1044071 commit 9ad4082

File tree

25 files changed

+958
-565
lines changed

25 files changed

+958
-565
lines changed

.kitchen.yml

-25
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,6 @@ suites:
4646
systems:
4747
- name: simple_regional_with_ipv6
4848
backend: local
49-
- name: "stub_domains"
50-
transport:
51-
root_module_directory: test/fixtures/stub_domains
52-
verifier:
53-
systems:
54-
- name: stub_domains
55-
backend: local
56-
controls:
57-
- gcloud
58-
- kubectl
59-
# Disabled due to issue #264
60-
# (https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/264)
61-
# - name: stub_domains_private
62-
# transport:
63-
# root_module_directory: test/fixtures/stub_domains_private
64-
# systems:
65-
# - name: stub_domains_private
66-
# backend: local
67-
- name: "upstream_nameservers"
68-
transport:
69-
root_module_directory: test/fixtures/upstream_nameservers
70-
verifier:
71-
systems:
72-
- name: upstream_nameservers
73-
backend: local
7449
- name: "stub_domains_upstream_nameservers"
7550
transport:
7651
root_module_directory: test/fixtures/stub_domains_upstream_nameservers

CONTRIBUTING.md

+7-18
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,14 @@ Integration tests are used to verify the behaviour of the root module,
4141
submodules, and example modules. Additions, changes, and fixes should
4242
be accompanied with tests.
4343

44-
The integration tests are run using [Kitchen][kitchen],
45-
[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These
46-
tools are packaged within a Docker image for convenience.
44+
The integration tests are run using[Cloud Foundation Toolkit CLI (CFT CLI)][https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/tree/main/cli],
45+
and [Blueprint Test][https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/tree/main/infra/blueprint-test]. The CFT CLI
46+
is packaged within a Docker image for convenience.
4747

4848
The general strategy for these tests is to verify the behaviour of the
4949
[example modules](./examples/), thus ensuring that the root module,
5050
submodules, and example modules are all functionally correct.
5151

52-
Six test-kitchen instances are defined:
53-
54-
- `deploy-service`
55-
- `node-pool`
56-
- `shared-vpc`
57-
- `simple-regional`
58-
- `simple-zonal`
59-
- `stub-domains`
60-
61-
The test-kitchen instances in `test/fixtures/` wrap identically-named examples in the `examples/` directory.`
62-
6352
### Test Environment
6453
The easiest way to test the module is in an isolated test project. The
6554
setup for such a project is defined in [test/setup](./test/setup/)
@@ -101,14 +90,14 @@ noninteractively, using the prepared test project.
10190
1. Run `make docker_run` to start the testing Docker container in
10291
interactive mode.
10392

104-
1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working
93+
1. Run `cft test run <EXAMPLE_NAME> --stage init` to initialize the working
10594
directory for an example module.
10695

107-
1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module.
96+
1. Run `cft test run <EXAMPLE_NAME> --stage apply` to apply the example module.
10897

109-
1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module.
98+
1. Run `cft test run <EXAMPLE_NAME> --stage verify` to test the example module.
11099

111-
1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module
100+
1. Run `cft test run <EXAMPLE_NAME> --stage destroy` to destroy the example module
112101
state.
113102

114103
## Linting and Formatting

build/int.cloudbuild.yaml

+26-10
Original file line numberDiff line numberDiff line change
@@ -200,36 +200,52 @@ steps:
200200
- verify simple-zonal-private-local
201201
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
202202
args: ['/bin/bash', '-c', 'cft test run TestSimpleZonalPrivate --stage teardown --verbose']
203-
- id: converge stub-domains-local
203+
- id: apply stub-domains-local
204204
waitFor:
205205
- create-all
206206
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
207-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge stub-domains-local']
207+
args: ['/bin/bash', '-c', 'cft test run TestStubDomains --stage apply --verbose --test-dir test/integration']
208208
- id: verify stub-domains-local
209209
waitFor:
210-
- converge stub-domains-local
210+
- apply stub-domains-local
211211
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
212-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify stub-domains-local']
212+
args: ['/bin/bash', '-c', 'cft test run TestStubDomains --stage verify --verbose --test-dir test/integration']
213213
- id: destroy stub-domains-local
214214
waitFor:
215215
- verify stub-domains-local
216216
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
217-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy stub-domains-local']
218-
- id: converge upstream-nameservers-local
217+
args: ['/bin/bash', '-c', 'cft test run TestStubDomains --stage destroy --verbose --test-dir test/integration']
218+
# Disabled: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/264
219+
# - id: apply stub-domains-private-local
220+
# waitFor:
221+
# - create-all
222+
# name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
223+
# args: ['/bin/bash', '-c', 'cft test run TestStubDomainsPrivate --stage apply --verbose --test-dir test/integration']
224+
# - id: verify stub-domains-private-local
225+
# waitFor:
226+
# - apply stub-domains-private-local
227+
# name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
228+
# args: ['/bin/bash', '-c', 'cft test run TestStubDomainsPrivate --stage verify --verbose --test-dir test/integration']
229+
# - id: destroy stub-domains-private-local
230+
# waitFor:
231+
# - verify stub-domains-private-local
232+
# name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
233+
# args: ['/bin/bash', '-c', 'cft test run TestStubDomainsPrivate --stage destroy --verbose --test-dir test/integration']
234+
- id: apply upstream-nameservers-local
219235
waitFor:
220236
- create-all
221237
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
222-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge upstream-nameservers-local']
238+
args: ['/bin/bash', '-c', 'cft test run TestUpstreamNameservers --stage apply --verbose --test-dir test/integration']
223239
- id: verify upstream-nameservers-local
224240
waitFor:
225-
- converge upstream-nameservers-local
241+
- apply upstream-nameservers-local
226242
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
227-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify upstream-nameservers-local']
243+
args: ['/bin/bash', '-c', 'cft test run TestUpstreamNameservers --stage verify --verbose --test-dir test/integration']
228244
- id: destroy upstream-nameservers-local
229245
waitFor:
230246
- verify upstream-nameservers-local
231247
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
232-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy upstream-nameservers-local']
248+
args: ['/bin/bash', '-c', 'cft test run TestUpstreamNameservers --stage destroy --verbose --test-dir test/integration']
233249
- id: converge stub-domains-upstream-nameservers-local
234250
waitFor:
235251
- create-all

test/fixtures/stub_domains/example.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
compute_engine_service_account = var.compute_engine_service_accounts[1]
19+
}
20+
1721
module "example" {
1822
source = "../../../examples/stub_domains"
1923

@@ -24,6 +28,6 @@ module "example" {
2428
subnetwork = google_compute_subnetwork.main.name
2529
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
2630
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
27-
compute_engine_service_account = var.compute_engine_service_accounts[1]
31+
compute_engine_service_account = local.compute_engine_service_account
2832
}
2933

test/fixtures/stub_domains/outputs.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,3 +56,11 @@ output "service_account" {
5656
description = "The service account to default running nodes as if not overridden in `node_pools`."
5757
value = module.example.service_account
5858
}
59+
60+
output "random_string" {
61+
value = random_string.suffix.result
62+
}
63+
64+
output "compute_engine_service_account" {
65+
value = local.compute_engine_service_account
66+
}

test/fixtures/stub_domains_private/main.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
compute_engine_service_account = var.compute_engine_service_accounts[1]
19+
}
20+
1721
resource "random_string" "suffix" {
1822
length = 4
1923
special = false
@@ -49,7 +53,7 @@ resource "google_compute_subnetwork" "main" {
4953
module "example" {
5054
source = "../../../examples/stub_domains_private"
5155

52-
compute_engine_service_account = var.compute_engine_service_accounts[1]
56+
compute_engine_service_account = local.compute_engine_service_account
5357
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
5458
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
5559
network = google_compute_network.main.name

test/fixtures/stub_domains_private/outputs.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,3 +56,11 @@ output "service_account" {
5656
description = "The service account to default running nodes as if not overridden in `node_pools`."
5757
value = module.example.service_account
5858
}
59+
60+
output "random_string" {
61+
value = random_string.suffix.result
62+
}
63+
64+
output "compute_engine_service_account" {
65+
value = local.compute_engine_service_account
66+
}

test/fixtures/upstream_nameservers/example.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
compute_engine_service_account = var.compute_engine_service_accounts[1]
19+
}
20+
1721
module "example" {
1822
source = "../../../examples/upstream_nameservers"
1923

@@ -24,6 +28,6 @@ module "example" {
2428
subnetwork = google_compute_subnetwork.main.name
2529
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
2630
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
27-
compute_engine_service_account = var.compute_engine_service_accounts[1]
31+
compute_engine_service_account = local.compute_engine_service_account
2832
}
2933

test/fixtures/upstream_nameservers/outputs.tf

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,3 +56,11 @@ output "service_account" {
5656
description = "The service account to default running nodes as if not overridden in `node_pools`."
5757
value = module.example.service_account
5858
}
59+
60+
output "random_string" {
61+
value = random_string.suffix.result
62+
}
63+
64+
output "compute_engine_service_account" {
65+
value = local.compute_engine_service_account
66+
}

test/integration/node_pool/testdata/TestNodePool.json

-7
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@
249249
"name": "default-pool",
250250
"networkConfig": {
251251
"podIpv4CidrBlock": "192.168.0.0/18",
252-
"podIpv4RangeUtilization": 0.0624,
253252
"podRange": "cft-gke-test-pods-RANDOM_STRING"
254253
},
255254
"podIpv4CidrSize": 24,
@@ -302,7 +301,6 @@
302301
"name": "nap-e2-medium-1d469r1p",
303302
"networkConfig": {
304303
"podIpv4CidrBlock": "192.168.0.0/18",
305-
"podIpv4RangeUtilization": 0.0624,
306304
"podRange": "cft-gke-test-pods-RANDOM_STRING"
307305
},
308306
"placementPolicy": {},
@@ -395,7 +393,6 @@
395393
"name": "pool-01",
396394
"networkConfig": {
397395
"podIpv4CidrBlock": "192.168.0.0/18",
398-
"podIpv4RangeUtilization": 0.0624,
399396
"podRange": "cft-gke-test-pods-RANDOM_STRING"
400397
},
401398
"podIpv4CidrSize": 24,
@@ -490,7 +487,6 @@
490487
"name": "pool-02",
491488
"networkConfig": {
492489
"podIpv4CidrBlock": "192.168.0.0/18",
493-
"podIpv4RangeUtilization": 0.0624,
494490
"podRange": "cft-gke-test-pods-RANDOM_STRING"
495491
},
496492
"podIpv4CidrSize": 24,
@@ -583,7 +579,6 @@
583579
"networkConfig": {
584580
"enablePrivateNodes": false,
585581
"podIpv4CidrBlock": "172.16.0.0/18",
586-
"podIpv4RangeUtilization": 0.0625,
587582
"podRange": "test"
588583
},
589584
"podIpv4CidrSize": 24,
@@ -671,7 +666,6 @@
671666
"name": "pool-04",
672667
"networkConfig": {
673668
"podIpv4CidrBlock": "192.168.0.0/18",
674-
"podIpv4RangeUtilization": 0.0624,
675669
"podRange": "cft-gke-test-pods-RANDOM_STRING"
676670
},
677671
"podIpv4CidrSize": 24,
@@ -759,7 +753,6 @@
759753
"name": "pool-05",
760754
"networkConfig": {
761755
"podIpv4CidrBlock": "192.168.0.0/18",
762-
"podIpv4RangeUtilization": 0.0624,
763756
"podRange": "cft-gke-test-pods-RANDOM_STRING"
764757
},
765758
"podIpv4CidrSize": 24,

test/integration/stub_domains/controls/gcloud.rb

-52
This file was deleted.

0 commit comments

Comments
 (0)