Skip to content

Commit 2cc11ee

Browse files
authored
chore: This updates instance-simple test to use new framework (#208)
* This adds an instance-simple integration test based on the GO test framework * Takes out the kitchen test and fixes versions in go.mod * Takes out the old kitchen test * Minor fixes Co-authored-by: Awais Malik <[email protected]>
1 parent 11523d3 commit 2cc11ee

File tree

15 files changed

+956
-130
lines changed

15 files changed

+956
-130
lines changed

.kitchen.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ suites:
4545
name: terraform
4646
command_timeout: 1800
4747
root_module_directory: test/fixtures/preemptible_and_regular_instance_templates/simple
48-
- name: instance_simple
49-
driver:
50-
name: terraform
51-
command_timeout: 1800
52-
root_module_directory: test/fixtures/compute_instance/simple
5348
- name: instance_simple_zone
5449
driver:
5550
name: terraform

build/int.cloudbuild.yaml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,28 @@ steps:
8181
- verify-preemptible-and-regular-instance-templates-simple-local
8282
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
8383
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy preemptible-and-regular-instance-templates-simple-local']
84-
- id: create-instance-simple-local
85-
wait_for:
84+
- id: go-init-instance-simple
85+
waitFor:
8686
- prepare
8787
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
88-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create instance-simple-local']
89-
- id: converge-instance-simple-local
90-
wait_for:
91-
- create-instance-simple-local
88+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=init go test -v -run TestInstanceSimpleModule ./... -p 1']
89+
- id: go-apply-instance-simple
90+
waitFor:
91+
- go-init-instance-simple
9292
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
93-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge instance-simple-local']
94-
- id: verify-instance-simple-local
95-
wait_for:
96-
- converge-instance-simple-local
93+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=apply go test -v -run TestInstanceSimpleModule ./... -p 1']
94+
timeout: 3600s
95+
- id: go-verify-instance-simple
96+
waitFor:
97+
- go-apply-instance-simple
9798
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
98-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify instance-simple-local']
99-
- id: destroy-instance-simple-local
100-
wait_for:
101-
- verify-instance-simple-local
99+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=verify go test -v -run TestInstanceSimpleModule ./... -p 1']
100+
- id: go-destroy-instance-simple
101+
waitFor:
102+
- go-verify-instance-simple
102103
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
103-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy instance-simple-local']
104+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=teardown go test -v -run TestInstanceSimpleModule ./... -p 1']
105+
timeout: 1800s
104106
- id: create-mig-simple-local
105107
wait_for:
106108
- prepare
@@ -126,7 +128,7 @@ steps:
126128
- destroy-it-simple-local
127129
- destroy-it-additional-disks-local
128130
- destroy-preemptible-and-regular-instance-templates-simple-local
129-
- destroy-instance-simple-local
131+
- go-destroy-instance-simple
130132
- destroy-mig-simple-local
131133
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
132134
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create mig-autoscaler-local']
@@ -150,7 +152,7 @@ steps:
150152
- destroy-it-simple-local
151153
- destroy-it-additional-disks-local
152154
- destroy-preemptible-and-regular-instance-templates-simple-local
153-
- destroy-instance-simple-local
155+
- go-destroy-instance-simple
154156
- destroy-mig-simple-local
155157
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
156158
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-simple-local']
@@ -174,7 +176,7 @@ steps:
174176
- destroy-it-simple-local
175177
- destroy-it-additional-disks-local
176178
- destroy-preemptible-and-regular-instance-templates-simple-local
177-
- destroy-instance-simple-local
179+
- go-destroy-instance-simple
178180
- destroy-mig-simple-local
179181
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
180182
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-named-ports-local']
@@ -198,7 +200,7 @@ steps:
198200
- destroy-it-simple-local
199201
- destroy-it-additional-disks-local
200202
- destroy-preemptible-and-regular-instance-templates-simple-local
201-
- destroy-instance-simple-local
203+
- go-destroy-instance-simple
202204
- destroy-mig-simple-local
203205
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
204206
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-static-ips-local']
@@ -222,7 +224,7 @@ steps:
222224
- destroy-it-simple-local
223225
- destroy-it-additional-disks-local
224226
- destroy-preemptible-and-regular-instance-templates-simple-local
225-
- destroy-instance-simple-local
227+
- go-destroy-instance-simple
226228
- destroy-mig-simple-local
227229
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
228230
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create mig-with-percent-simple-local']
@@ -241,6 +243,7 @@ steps:
241243
- verify-mig-with-percent-simple-local
242244
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
243245
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy mig-with-percent-simple-local']
246+
244247
tags:
245248
- 'ci'
246249
- 'integration'

test/fixtures/compute_instance/simple/network.tf

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/compute_instance/simple/terraform.tfvars

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/compute_instance/simple/main.tf renamed to test/fixtures/instance_simple/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
module "instance_simple" {
19-
source = "../../../../examples/compute_instance/simple"
19+
source = "../../../examples/compute_instance/simple"
2020
project_id = var.project_id
2121
region = "us-central1"
2222
subnetwork = google_compute_subnetwork.main.self_link
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/network.tf

test/fixtures/compute_instance/simple/outputs.tf renamed to test/fixtures/instance_simple/outputs.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ output "project_id" {
2424
value = var.project_id
2525
}
2626

27-
28-
27+
output "service_account" {
28+
description = "Service account to attach to the instance"
29+
value = var.service_account
30+
}

test/integration/discover_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 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 test
16+
17+
import (
18+
// should be imported to enable testing for GO modules
19+
"testing"
20+
21+
// should be imported to use terraform helpers in blueprints test framework
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23+
)
24+
25+
// entry function for the test; can be named as Test*
26+
func TestAll(t *testing.T) {
27+
// the helper to autodiscover and test blueprint examples
28+
tft.AutoDiscoverAndTest(t)
29+
}

0 commit comments

Comments
 (0)