Skip to content

Commit 79271bd

Browse files
chore: port mysql-public test to new framework (#245)
* Adds a sample test based on the new test framework * Adds the verbose flag to the CI tests * Minor comments fixes * Minor formatting changes and added assertion for 1 auth network and removed kitchen test from cloud build * Update build/int.cloudbuild.yaml Co-authored-by: Awais Malik <[email protected]> Co-authored-by: Bharath KKB <[email protected]>
1 parent 3064744 commit 79271bd

File tree

5 files changed

+819
-9
lines changed

5 files changed

+819
-9
lines changed

build/int.cloudbuild.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,27 @@ steps:
6363
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy mssql-public-local']
6464
timeout: 1800s
6565

66-
- id: converge-mysql-public-local
66+
- id: go-init-mysql-public
6767
waitFor:
68-
- create-all
68+
- prepare
69+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
70+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=init go test -v -run TestMySqlPublicModule ./... -p 1']
71+
- id: go-apply-mysql-public
72+
waitFor:
73+
- go-init-mysql-public
6974
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
70-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge mysql-public-local']
75+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=apply go test -v -run TestMySqlPublicModule ./... -p 1']
7176
timeout: 3600s
72-
- id: verify-mysql-public-local
77+
- id: go-verify-mysql-public
7378
waitFor:
74-
- converge-mysql-public-local
79+
- go-apply-mysql-public
7580
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
76-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify mysql-public-local']
77-
- id: destroy-mysql-public-local
81+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=verify go test -v -run TestMySqlPublicModule ./... -p 1']
82+
- id: go-destroy-mysql-public
7883
waitFor:
79-
- verify-mysql-public-local
84+
- go-verify-mysql-public
8085
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
81-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy mysql-public-local']
86+
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=teardown go test -v -run TestMySqlPublicModule ./... -p 1']
8287
timeout: 1800s
8388

8489
- id: converge-mysql-ha-local

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+
}

test/integration/go.mod

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module github.com/terraform-google-modules/terraform-google-sql-db/test/integration
2+
3+
go 1.17
4+
5+
require (
6+
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.0.0-20210818060910-07c4cb2d2107
7+
github.com/stretchr/testify v1.7.0
8+
)
9+
10+
require (
11+
github.com/agext/levenshtein v1.2.1 // indirect
12+
github.com/apparentlymart/go-textseg v1.0.0 // indirect
13+
github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/gruntwork-io/terratest v0.35.6 // indirect
16+
github.com/hashicorp/errwrap v1.0.0 // indirect
17+
github.com/hashicorp/go-multierror v1.1.0 // indirect
18+
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
19+
github.com/hashicorp/terraform-json v0.9.0 // indirect
20+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
21+
github.com/mitchellh/go-testing-interface v1.14.2-0.20210217184823-a52172cd2f64 // indirect
22+
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
23+
github.com/pmezard/go-difflib v1.0.0 // indirect
24+
github.com/tidwall/gjson v1.8.0 // indirect
25+
github.com/tidwall/match v1.0.3 // indirect
26+
github.com/tidwall/pretty v1.1.0 // indirect
27+
github.com/zclconf/go-cty v1.2.1 // indirect
28+
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
29+
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect
30+
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 // indirect
31+
golang.org/x/text v0.3.6 // indirect
32+
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
33+
)

0 commit comments

Comments
 (0)