Skip to content

Commit dd2d3b7

Browse files
authored
chore: Update to new blueprints test framework (#77)
1 parent b9b7003 commit dd2d3b7

File tree

35 files changed

+979
-585
lines changed

35 files changed

+979
-585
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ Integration tests are used to verify the behaviour of the root module,
2727
submodules, and example modules. Additions, changes, and fixes should
2828
be accompanied with tests.
2929

30-
The integration tests are run using [Kitchen][kitchen],
31-
[Kitchen-Terraform][kitchen-terraform], and [InSpec][inspec]. These
32-
tools are packaged within a Docker image for convenience.
30+
The integration tests are run using Golang and
31+
are packaged within a Docker image for convenience.
3332

3433
The general strategy for these tests is to verify the behaviour of the
3534
[example modules](./examples/), thus ensuring that the root module,
@@ -63,18 +62,7 @@ noninteractively, using the prepared test project.
6362

6463
### Interactive Execution
6564

66-
1. Run `make docker_run` to start the testing Docker container in
67-
interactive mode.
68-
69-
1. Run `kitchen_do create <EXAMPLE_NAME>` to initialize the working
70-
directory for an example module.
71-
72-
1. Run `kitchen_do converge <EXAMPLE_NAME>` to apply the example module.
73-
74-
1. Run `kitchen_do verify <EXAMPLE_NAME>` to test the example module.
75-
76-
1. Run `kitchen_do destroy <EXAMPLE_NAME>` to destroy the example module
77-
state.
65+
Review the [framework documentation](https://pkg.go.dev/github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test#readme-4-test-execution) to learn how to execute tests.
7866

7967
## Linting and Formatting
8068

@@ -90,9 +78,6 @@ Run `make docker_test_lint`.
9078
[gofmt]: https://golang.org/cmd/gofmt/
9179
[google-cloud-sdk]: https://cloud.google.com/sdk/install
9280
[hadolint]: https://github.com/hadolint/hadolint
93-
[inspec]: https://inspec.io/
94-
[kitchen-terraform]: https://github.com/newcontext-oss/kitchen-terraform
95-
[kitchen]: https://kitchen.ci/
9681
[make]: https://en.wikipedia.org/wiki/Make_(software)
9782
[shellcheck]: https://www.shellcheck.net/
9883
[terraform-docs]: https://github.com/segmentio/terraform-docs

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Make will use bash instead of sh
1919
SHELL := /usr/bin/env bash
2020

21-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1.0
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1
2222
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2323
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2424

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you find incompatibilities using Terraform `>=0.13`, please open an issue.
1919

2020
If you haven't [upgraded][terraform-0.13-upgrade] and need a Terraform
2121
0.12.x-compatible version of this module, the last released version
22-
intended for Terraform 0.12.x is [v1.5.0](https://registry.terraform.io/modules/terraform-google-modules/-event-function/google/v1.5.0).
22+
intended for Terraform 0.12.x is [v1.6.0](https://registry.terraform.io/modules/terraform-google-modules/-event-function/google/v1.6.0).
2323

2424
## Usage
2525

@@ -100,8 +100,7 @@ from which this module will be invoked:
100100

101101
- [Terraform](https://www.terraform.io/downloads.html) >= 0.13.0
102102
- [Terraform Provider for Archive][terraform-provider-archive-site]
103-
v1.2
104-
- [Terraform Provider for Google Cloud Platform][terraform-provider-gcp-site] v2.5
103+
- [Terraform Provider for Google Cloud Platform][terraform-provider-gcp-site]
105104

106105
### IAM Roles
107106

build/int.cloudbuild.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ steps:
2323
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
2424
- id: create
2525
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
26-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
26+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cd test/integration && RUN_STAGE=init go test -v ./... -p 1']
2727
- id: converge
2828
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
29-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
29+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cd test/integration && RUN_STAGE=apply go test -v ./... -p 1']
3030
- id: verify
3131
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
32-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify']
32+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cd test/integration && RUN_STAGE=verify go test -v ./... -p 1']
3333
- id: destroy
3434
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
35+
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && source_test_env && init_credentials && cd test/integration && RUN_STAGE=teardown go test -v ./... -p 1']
3636
tags:
3737
- 'ci'
3838
- 'integration'
3939
substitutions:
4040
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
41-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.0'
41+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1'

examples/automatic-labelling-from-repository/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ this directory:
3232
| Name | Description |
3333
|------|-------------|
3434
| compute\_instance\_name | The name of the unlabelled Compute instance. |
35+
| project\_id | The ID of the project to which resources are applied. |
36+
| zone | The zone in which resources are applied. |
3537

3638
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3739

examples/automatic-labelling-from-repository/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ output "compute_instance_name" {
1818
value = google_compute_instance.main.name
1919
description = "The name of the unlabelled Compute instance."
2020
}
21+
22+
output "project_id" {
23+
value = var.project_id
24+
description = "The ID of the project to which resources are applied."
25+
}
26+
27+
output "zone" {
28+
value = var.zone
29+
description = "The zone in which resources are applied."
30+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# https://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
16-
# frozen_string_literal: true
17-
require "json"
18-
19-
control "automatically labelled" do
20-
describe google_project(project: attribute("test_project_id")).label_value_by_key('test') do
21-
it {should match '^(foobar)$' }
22-
end
23-
end
15+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: delete-vms-without-cmek
19+
spec:
20+
skip: true

examples/dynamic-files/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ this directory:
2727
| Name | Description |
2828
|------|-------------|
2929
| function\_name | The name of the function created |
30+
| project\_id | The project in which resources are applied. |
3031
| random\_file\_string | The content of the terraform created file in the source directory. |
3132
| region | The region in which resources are applied. |
3233

examples/dynamic-files/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
output "project_id" {
18+
value = var.project_id
19+
description = "The project in which resources are applied."
20+
}
21+
1722
output "region" {
1823
value = var.region
1924
description = "The region in which resources are applied."

kitchen.yml

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

0 commit comments

Comments
 (0)