Skip to content

Commit 2c640ba

Browse files
authored
Merge branch 'master' into ap/borninfleet
2 parents e8d934a + 0a2d505 commit 2c640ba

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

test/integration/deploy_service/deploy_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestDeployService(t *testing.T) {
4343
k8sOpts := k8s.KubectlOptions{}
4444
listServices, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "svc", "terraform-example", "-o", "json")
4545
assert.NoError(err)
46-
kubeService := utils.ParseJSONResult(t, listServices)
46+
kubeService := testutils.ParseKubectlJSONResult(t, listServices)
4747
serviceIp := kubeService.Get("status.loadBalancer.ingress").Array()[0].Get("ip")
4848
serviceUrl := fmt.Sprintf("http://%s:8080", serviceIp)
4949

test/integration/simple_zonal/simple_zonal_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
2222
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
2323
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
24-
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
2524
"github.com/gruntwork-io/terratest/modules/k8s"
2625
"github.com/stretchr/testify/assert"
2726
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
@@ -78,11 +77,11 @@ func TestSimpleZonal(t *testing.T) {
7877
k8sOpts := k8s.KubectlOptions{}
7978
configNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "config-management-system", "-o", "json")
8079
assert.NoError(err)
81-
configkubeNS := utils.ParseJSONResult(t, configNameSpace)
80+
configkubeNS := testutils.ParseKubectlJSONResult(t, configNameSpace)
8281
assert.Contains(configkubeNS.Get("metadata.name").String(), "config-management-system", "Namespace is Functional")
8382
gateKeeperNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "gatekeeper-system", "-o", "json")
8483
assert.NoError(err)
85-
gateKeeperkubeNS := utils.ParseJSONResult(t, gateKeeperNameSpace)
84+
gateKeeperkubeNS := testutils.ParseKubectlJSONResult(t, gateKeeperNameSpace)
8685
assert.Contains(gateKeeperkubeNS.Get("metadata.name").String(), "gatekeeper-system", "Namespace is Functional")
8786
})
8887

test/integration/simple_zonal_with_asm/simple_zonal_with_asm_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
2222
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23-
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
2423
"github.com/gruntwork-io/terratest/modules/k8s"
2524
"github.com/stretchr/testify/assert"
2625
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
@@ -50,11 +49,11 @@ func TestSimpleZonalWithASM(t *testing.T) {
5049
k8sOpts := k8s.KubectlOptions{}
5150
listNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "istio-system", "-o", "json")
5251
assert.NoError(err)
53-
kubeNS := utils.ParseJSONResult(t, listNameSpace)
52+
kubeNS := testutils.ParseKubectlJSONResult(t, listNameSpace)
5453
assert.Contains(kubeNS.Get("metadata.name").String(), "istio-system", "Namespace is Functional")
5554
listConfigMap, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "configmap", "asm-options", "-n", "istio-system", "-o", "json")
5655
assert.NoError(err)
57-
kubeCM := utils.ParseJSONResult(t, listConfigMap)
56+
kubeCM := testutils.ParseKubectlJSONResult(t, listConfigMap)
5857
assert.Contains(kubeCM.Get("metadata.name").String(), "asm-options", "Configmap is Present")
5958

6059
})

test/integration/testutils/json.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2024 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 testutils
16+
17+
import (
18+
"bytes"
19+
"testing"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
22+
"github.com/tidwall/gjson"
23+
)
24+
25+
var (
26+
KubectlTransientErrors = []string{
27+
"E0222 .* the server is currently unable to handle the request",
28+
}
29+
)
30+
31+
// Filter transient errors from kubectl output
32+
func ParseKubectlJSONResult(t testing.TB, s string) gjson.Result {
33+
bstring := []byte(s)
34+
35+
for _, v := range KubectlTransientErrors {
36+
bstring = bytes.Replace(bstring, []byte(v), []byte(""), -1)
37+
}
38+
39+
return utils.ParseJSONResult(t, string(bstring))
40+
}

0 commit comments

Comments
 (0)