Skip to content

Commit

Permalink
chore: This updates instance-simple test to use new framework (#208)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
g-awmalik and g-awmalik authored Oct 1, 2021
1 parent 11523d3 commit 2cc11ee
Show file tree
Hide file tree
Showing 15 changed files with 956 additions and 130 deletions.
5 changes: 0 additions & 5 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ suites:
name: terraform
command_timeout: 1800
root_module_directory: test/fixtures/preemptible_and_regular_instance_templates/simple
- name: instance_simple
driver:
name: terraform
command_timeout: 1800
root_module_directory: test/fixtures/compute_instance/simple
- name: instance_simple_zone
driver:
name: terraform
Expand Down
43 changes: 23 additions & 20 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,28 @@ steps:
- verify-preemptible-and-regular-instance-templates-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy preemptible-and-regular-instance-templates-simple-local']
- id: create-instance-simple-local
wait_for:
- id: go-init-instance-simple
waitFor:
- prepare
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create instance-simple-local']
- id: converge-instance-simple-local
wait_for:
- create-instance-simple-local
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=init go test -v -run TestInstanceSimpleModule ./... -p 1']
- id: go-apply-instance-simple
waitFor:
- go-init-instance-simple
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge instance-simple-local']
- id: verify-instance-simple-local
wait_for:
- converge-instance-simple-local
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=apply go test -v -run TestInstanceSimpleModule ./... -p 1']
timeout: 3600s
- id: go-verify-instance-simple
waitFor:
- go-apply-instance-simple
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify instance-simple-local']
- id: destroy-instance-simple-local
wait_for:
- verify-instance-simple-local
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=verify go test -v -run TestInstanceSimpleModule ./... -p 1']
- id: go-destroy-instance-simple
waitFor:
- go-verify-instance-simple
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy instance-simple-local']
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=teardown go test -v -run TestInstanceSimpleModule ./... -p 1']
timeout: 1800s
- id: create-mig-simple-local
wait_for:
- prepare
Expand All @@ -126,7 +128,7 @@ steps:
- destroy-it-simple-local
- destroy-it-additional-disks-local
- destroy-preemptible-and-regular-instance-templates-simple-local
- destroy-instance-simple-local
- go-destroy-instance-simple
- destroy-mig-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create mig-autoscaler-local']
Expand All @@ -150,7 +152,7 @@ steps:
- destroy-it-simple-local
- destroy-it-additional-disks-local
- destroy-preemptible-and-regular-instance-templates-simple-local
- destroy-instance-simple-local
- go-destroy-instance-simple
- destroy-mig-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-simple-local']
Expand All @@ -174,7 +176,7 @@ steps:
- destroy-it-simple-local
- destroy-it-additional-disks-local
- destroy-preemptible-and-regular-instance-templates-simple-local
- destroy-instance-simple-local
- go-destroy-instance-simple
- destroy-mig-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-named-ports-local']
Expand All @@ -198,7 +200,7 @@ steps:
- destroy-it-simple-local
- destroy-it-additional-disks-local
- destroy-preemptible-and-regular-instance-templates-simple-local
- destroy-instance-simple-local
- go-destroy-instance-simple
- destroy-mig-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create umig-static-ips-local']
Expand All @@ -222,7 +224,7 @@ steps:
- destroy-it-simple-local
- destroy-it-additional-disks-local
- destroy-preemptible-and-regular-instance-templates-simple-local
- destroy-instance-simple-local
- go-destroy-instance-simple
- destroy-mig-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create mig-with-percent-simple-local']
Expand All @@ -241,6 +243,7 @@ steps:
- verify-mig-with-percent-simple-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy mig-with-percent-simple-local']

tags:
- 'ci'
- 'integration'
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/compute_instance/simple/network.tf

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/compute_instance/simple/terraform.tfvars

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


module "instance_simple" {
source = "../../../../examples/compute_instance/simple"
source = "../../../examples/compute_instance/simple"
project_id = var.project_id
region = "us-central1"
subnetwork = google_compute_subnetwork.main.self_link
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/instance_simple/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ output "project_id" {
value = var.project_id
}



output "service_account" {
description = "Service account to attach to the instance"
value = var.service_account
}
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions test/integration/discover_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package test

import (
// should be imported to enable testing for GO modules
"testing"

// should be imported to use terraform helpers in blueprints test framework
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
)

// entry function for the test; can be named as Test*
func TestAll(t *testing.T) {
// the helper to autodiscover and test blueprint examples
tft.AutoDiscoverAndTest(t)
}
8 changes: 8 additions & 0 deletions test/integration/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/terraform-google-modules/terraform-google-sql-db/test/integration

go 1.16

require (
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.0.0-20210930021043-39b4ef08bb23
github.com/stretchr/testify v1.7.0
)
Loading

0 comments on commit 2cc11ee

Please sign in to comment.