Skip to content

Commit 9eb26b9

Browse files
akshaybathija-githubAkshay Bathija
and
Akshay Bathija
authored
chore: Migrating Test Framework (terraform-google-modules#1548)
Co-authored-by: Akshay Bathija <[email protected]>
1 parent e9a72cf commit 9eb26b9

File tree

16 files changed

+952
-1465
lines changed

16 files changed

+952
-1465
lines changed

build/int.cloudbuild.yaml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,26 @@ steps:
6161
- verify shared-vpc-local
6262
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
6363
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy shared-vpc-local']
64-
- id: converge safer-cluster-local
64+
- id: init safer-cluster-local
6565
waitFor:
6666
- create all
6767
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
68-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge safer-cluster-local']
68+
args: ['/bin/bash', '-c', 'cft test run TestSaferCluster --stage init --verbose']
69+
- id: apply safer-cluster-local
70+
waitFor:
71+
- init safer-cluster-local
72+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
73+
args: ['/bin/bash', '-c', 'cft test run TestSaferCluster --stage apply --verbose']
6974
- id: verify safer-cluster-local
7075
waitFor:
71-
- converge safer-cluster-local
76+
- apply safer-cluster-local
7277
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
73-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify safer-cluster-local']
78+
args: ['/bin/bash', '-c', 'cft test run TestSaferCluster --stage verify --verbose']
7479
- id: destroy safer-cluster-local
7580
waitFor:
7681
- verify safer-cluster-local
7782
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
78-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy safer-cluster-local']
83+
args: ['/bin/bash', '-c', 'cft test run TestSaferCluster --stage destroy --verbose']
7984
- id: converge simple-regional-local
8085
waitFor:
8186
- create all
@@ -276,21 +281,26 @@ steps:
276281
- verify simple-windows-node-pool-local
277282
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
278283
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy simple-windows-node-pool-local']
279-
- id: converge deploy-service-local
284+
- id: init deploy-service-local
280285
waitFor:
281286
- create all
282287
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
283-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge deploy-service-local']
288+
args: ['/bin/bash', '-c', 'cft test run TestDeployService --stage init --verbose']
289+
- id: apply deploy-service-local
290+
waitFor:
291+
- init deploy-service-local
292+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
293+
args: ['/bin/bash', '-c', 'cft test run TestDeployService --stage apply --verbose']
284294
- id: verify deploy-service-local
285295
waitFor:
286-
- converge deploy-service-local
296+
- apply deploy-service-local
287297
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
288-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify deploy-service-local']
298+
args: ['/bin/bash', '-c', 'cft test run TestDeployService --stage verify --verbose']
289299
- id: destroy deploy-service-local
290300
waitFor:
291301
- verify deploy-service-local
292302
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
293-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy deploy-service-local']
303+
args: ['/bin/bash', '-c', 'cft test run TestDeployService --stage destroy --verbose']
294304
- id: converge node-pool-local
295305
waitFor:
296306
- create all
@@ -306,21 +316,26 @@ steps:
306316
- verify node-pool-local
307317
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
308318
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy node-pool-local']
309-
- id: converge sandbox-enabled-local
319+
- id: init sandbox-enabled-local
310320
waitFor:
311321
- create all
312322
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
313-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge sandbox-enabled-local']
323+
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage init --verbose']
324+
- id: apply sandbox-enabled-local
325+
waitFor:
326+
- init sandbox-enabled-local
327+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
328+
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage apply --verbose']
314329
- id: verify sandbox-enabled-local
315330
waitFor:
316-
- converge sandbox-enabled-local
331+
- apply sandbox-enabled-local
317332
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
318-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify sandbox-enabled-local']
333+
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage verify --verbose']
319334
- id: destroy sandbox-enabled-local
320335
waitFor:
321336
- verify sandbox-enabled-local
322337
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
323-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy sandbox-enabled-local']
338+
args: ['/bin/bash', '-c', 'cft test run TestSandboxEnabled --stage destroy --verbose']
324339
- id: converge workload-identity-local
325340
waitFor:
326341
- create all

test/integration/deploy_service/controls/gcloud.rb

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

test/integration/deploy_service/controls/kubectl.rb

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2022 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+
package deploy_service
15+
16+
import (
17+
"fmt"
18+
"io/ioutil"
19+
"net/http"
20+
"testing"
21+
"time"
22+
23+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
24+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
25+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
26+
"github.com/gruntwork-io/terratest/modules/k8s"
27+
"github.com/stretchr/testify/assert"
28+
)
29+
30+
func TestDeployService(t *testing.T) {
31+
bpt := tft.NewTFBlueprintTest(t)
32+
33+
bpt.DefineVerify(func(assert *assert.Assertions) {
34+
// bpt.DefaultVerify(assert)
35+
36+
projectId := bpt.GetStringOutput("project_id")
37+
location := bpt.GetStringOutput("location")
38+
clusterName := bpt.GetStringOutput("cluster_name")
39+
gcloud.Runf(t, "container clusters get-credentials %s --region %s --project %s", clusterName, location, projectId)
40+
k8sOpts := k8s.KubectlOptions{}
41+
listServices, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "svc", "terraform-example", "-o", "json")
42+
assert.NoError(err)
43+
kubeService := utils.ParseJSONResult(t, listServices)
44+
serviceIp := kubeService.Get("status.loadBalancer.ingress").Array()[0].Get("ip")
45+
serviceUrl := fmt.Sprintf("http://%s:8080", serviceIp)
46+
47+
pollHTTPEndPoint := func(cmd string) func() (bool, error) {
48+
return func() (bool, error) {
49+
_, err := http.Get(cmd)
50+
if assert.NoError(err) {
51+
return false, nil
52+
}
53+
return true, nil
54+
}
55+
}
56+
57+
utils.Poll(t, pollHTTPEndPoint(serviceUrl), 20, 10*time.Second)
58+
response, err := http.Get(serviceUrl)
59+
assert.NoError(err)
60+
responseData, err := ioutil.ReadAll(response.Body)
61+
assert.NoError(err)
62+
assert.Contains(string(responseData), "Thank you for using nginx.", "Service is Functional")
63+
})
64+
65+
bpt.Test()
66+
}

test/integration/deploy_service/inspec.yml

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

test/integration/go.mod

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,9 @@
11
module github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration
22

3-
go 1.18
3+
go 1.16
44

55
require (
6-
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.4.1
7-
github.com/go-openapi/jsonreference v0.19.5 // indirect
8-
github.com/go-openapi/swag v0.19.14 // indirect
9-
github.com/google/go-cmp v0.5.8 // indirect
10-
github.com/stretchr/testify v1.8.1
11-
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
12-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
13-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
14-
google.golang.org/protobuf v1.28.0 // indirect
15-
)
16-
17-
require (
18-
cloud.google.com/go v0.83.0 // indirect
19-
cloud.google.com/go/storage v1.10.0 // indirect
20-
github.com/PuerkitoBio/purell v1.1.1 // indirect
21-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
22-
github.com/agext/levenshtein v1.2.3 // indirect
23-
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
24-
github.com/aws/aws-sdk-go v1.40.56 // indirect
25-
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
26-
github.com/davecgh/go-spew v1.1.1 // indirect
27-
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
28-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
29-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
30-
github.com/golang/protobuf v1.5.2 // indirect
31-
github.com/golang/snappy v0.0.3 // indirect
32-
github.com/google/gnostic v0.5.7-v3refs // indirect
33-
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
34-
github.com/gruntwork-io/terratest v0.40.7 // indirect
35-
github.com/hashicorp/errwrap v1.0.0 // indirect
36-
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
37-
github.com/hashicorp/go-getter v1.6.1 // indirect
38-
github.com/hashicorp/go-multierror v1.1.0 // indirect
39-
github.com/hashicorp/go-safetemp v1.0.0 // indirect
40-
github.com/hashicorp/go-version v1.3.0 // indirect
41-
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
42-
github.com/hashicorp/terraform-json v0.13.0 // indirect
43-
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
44-
github.com/jmespath/go-jmespath v0.4.0 // indirect
45-
github.com/josharian/intern v1.0.0 // indirect
46-
github.com/jstemmer/go-junit-report v0.9.1 // indirect
47-
github.com/klauspost/compress v1.13.0 // indirect
48-
github.com/mailru/easyjson v0.7.6 // indirect
49-
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
50-
github.com/mitchellh/go-homedir v1.1.0 // indirect
51-
github.com/mitchellh/go-testing-interface v1.14.2-0.20210217184823-a52172cd2f64 // indirect
52-
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
53-
github.com/pmezard/go-difflib v1.0.0 // indirect
54-
github.com/tidwall/gjson v1.12.1 // indirect
55-
github.com/tidwall/match v1.1.1 // indirect
56-
github.com/tidwall/pretty v1.2.0 // indirect
57-
github.com/tidwall/sjson v1.2.4 // indirect
58-
github.com/tmccombs/hcl2json v0.3.3 // indirect
59-
github.com/ulikunitz/xz v0.5.8 // indirect
60-
github.com/zclconf/go-cty v1.9.1 // indirect
61-
go.opencensus.io v0.23.0 // indirect
62-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
63-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
64-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
65-
golang.org/x/text v0.3.7 // indirect
66-
golang.org/x/tools v0.1.10 // indirect
67-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
68-
google.golang.org/api v0.47.0 // indirect
69-
google.golang.org/appengine v1.6.7 // indirect
70-
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
71-
google.golang.org/grpc v1.38.0 // indirect
72-
gopkg.in/yaml.v2 v2.4.0 // indirect
73-
gopkg.in/yaml.v3 v3.0.1 // indirect
74-
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
75-
sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect
6+
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.0.0-20220317050137-1c8897fbd42c
7+
github.com/gruntwork-io/terratest v0.35.6
8+
github.com/stretchr/testify v1.7.0
769
)

0 commit comments

Comments
 (0)