diff --git a/test/integration/deploy_service/deploy_service_test.go b/test/integration/deploy_service/deploy_service_test.go index 793763d03b..c87470d44b 100755 --- a/test/integration/deploy_service/deploy_service_test.go +++ b/test/integration/deploy_service/deploy_service_test.go @@ -43,7 +43,7 @@ func TestDeployService(t *testing.T) { k8sOpts := k8s.KubectlOptions{} listServices, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "svc", "terraform-example", "-o", "json") assert.NoError(err) - kubeService := utils.ParseJSONResult(t, listServices) + kubeService := testutils.ParseKubectlJSONResult(t, listServices) serviceIp := kubeService.Get("status.loadBalancer.ingress").Array()[0].Get("ip") serviceUrl := fmt.Sprintf("http://%s:8080", serviceIp) diff --git a/test/integration/simple_zonal/simple_zonal_test.go b/test/integration/simple_zonal/simple_zonal_test.go index 38b79b3672..cb5c796995 100644 --- a/test/integration/simple_zonal/simple_zonal_test.go +++ b/test/integration/simple_zonal/simple_zonal_test.go @@ -21,7 +21,6 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" - "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" "github.com/gruntwork-io/terratest/modules/k8s" "github.com/stretchr/testify/assert" "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" @@ -78,11 +77,11 @@ func TestSimpleZonal(t *testing.T) { k8sOpts := k8s.KubectlOptions{} configNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "config-management-system", "-o", "json") assert.NoError(err) - configkubeNS := utils.ParseJSONResult(t, configNameSpace) + configkubeNS := testutils.ParseKubectlJSONResult(t, configNameSpace) assert.Contains(configkubeNS.Get("metadata.name").String(), "config-management-system", "Namespace is Functional") gateKeeperNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "gatekeeper-system", "-o", "json") assert.NoError(err) - gateKeeperkubeNS := utils.ParseJSONResult(t, gateKeeperNameSpace) + gateKeeperkubeNS := testutils.ParseKubectlJSONResult(t, gateKeeperNameSpace) assert.Contains(gateKeeperkubeNS.Get("metadata.name").String(), "gatekeeper-system", "Namespace is Functional") }) diff --git a/test/integration/simple_zonal_with_asm/simple_zonal_with_asm_test.go b/test/integration/simple_zonal_with_asm/simple_zonal_with_asm_test.go index 7e10477ac1..0d8e363b7a 100644 --- a/test/integration/simple_zonal_with_asm/simple_zonal_with_asm_test.go +++ b/test/integration/simple_zonal_with_asm/simple_zonal_with_asm_test.go @@ -20,7 +20,6 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" - "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" "github.com/gruntwork-io/terratest/modules/k8s" "github.com/stretchr/testify/assert" "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" @@ -50,11 +49,11 @@ func TestSimpleZonalWithASM(t *testing.T) { k8sOpts := k8s.KubectlOptions{} listNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "istio-system", "-o", "json") assert.NoError(err) - kubeNS := utils.ParseJSONResult(t, listNameSpace) + kubeNS := testutils.ParseKubectlJSONResult(t, listNameSpace) assert.Contains(kubeNS.Get("metadata.name").String(), "istio-system", "Namespace is Functional") listConfigMap, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "configmap", "asm-options", "-n", "istio-system", "-o", "json") assert.NoError(err) - kubeCM := utils.ParseJSONResult(t, listConfigMap) + kubeCM := testutils.ParseKubectlJSONResult(t, listConfigMap) assert.Contains(kubeCM.Get("metadata.name").String(), "asm-options", "Configmap is Present") }) diff --git a/test/integration/testutils/json.go b/test/integration/testutils/json.go new file mode 100644 index 0000000000..675e513fe6 --- /dev/null +++ b/test/integration/testutils/json.go @@ -0,0 +1,40 @@ +// Copyright 2024 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 testutils + +import ( + "bytes" + "testing" + + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" + "github.com/tidwall/gjson" +) + +var ( + KubectlTransientErrors = []string{ + "E0222 .* the server is currently unable to handle the request", + } +) + +// Filter transient errors from kubectl output +func ParseKubectlJSONResult(t testing.TB, s string) gjson.Result { + bstring := []byte(s) + + for _, v := range KubectlTransientErrors { + bstring = bytes.Replace(bstring, []byte(v), []byte(""), -1) + } + + return utils.ParseJSONResult(t, string(bstring)) +}