diff --git a/test/integration/deploy_service/deploy_service_test.go b/test/integration/deploy_service/deploy_service_test.go index 8c51d52edc..3e7a1a8817 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 := testutils.ParseKubectlJSONResult(t, listServices) + kubeService := utils.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/sandbox_enabled/sandbox_enabled_test.go b/test/integration/sandbox_enabled/sandbox_enabled_test.go index 6d7a92f362..2be5a898e5 100644 --- a/test/integration/sandbox_enabled/sandbox_enabled_test.go +++ b/test/integration/sandbox_enabled/sandbox_enabled_test.go @@ -22,7 +22,6 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" "github.com/stretchr/testify/assert" "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" - gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils" ) func TestSandboxEnabled(t *testing.T) { @@ -33,7 +32,7 @@ func TestSandboxEnabled(t *testing.T) { bpt.DefineVerify(func(assert *assert.Assertions) { //Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token // bpt.DefaultVerify(assert) - gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources + testutils.TGKEVerify(t, bpt, assert) // Verify Resources projectId := bpt.GetStringOutput("project_id") location := bpt.GetStringOutput("location") diff --git a/test/integration/simple_autopilot_private_non_default_sa/simple_autopilot_private_non_default_sa_test.go b/test/integration/simple_autopilot_private_non_default_sa/simple_autopilot_private_non_default_sa_test.go index 33e6bc5e9e..7d00a3b1ad 100644 --- a/test/integration/simple_autopilot_private_non_default_sa/simple_autopilot_private_non_default_sa_test.go +++ b/test/integration/simple_autopilot_private_non_default_sa/simple_autopilot_private_non_default_sa_test.go @@ -22,11 +22,10 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" "github.com/stretchr/testify/assert" "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" - "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils" ) func TestSimpleAutopilotPrivateNonDefaultSA(t *testing.T) { - projectID := utils.GetTestProjectFromSetup(t, 1) + projectID := testutils.GetTestProjectFromSetup(t, 1) bpt := tft.NewTFBlueprintTest(t, tft.WithVars(map[string]interface{}{"project_id": projectID}), tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), diff --git a/test/integration/simple_zonal/simple_zonal_test.go b/test/integration/simple_zonal/simple_zonal_test.go index a29082134f..ec7d84b946 100644 --- a/test/integration/simple_zonal/simple_zonal_test.go +++ b/test/integration/simple_zonal/simple_zonal_test.go @@ -21,6 +21,7 @@ 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" @@ -77,7 +78,7 @@ 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 := testutils.ParseKubectlJSONResult(t, configNameSpace) + configkubeNS := utils.ParseKubectlJSONResult(t, configNameSpace) assert.Contains(configkubeNS.Get("metadata.name").String(), "config-management-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 0d8e363b7a..33791e9fa7 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,6 +20,7 @@ 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" @@ -49,11 +50,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 := testutils.ParseKubectlJSONResult(t, listNameSpace) + kubeNS := utils.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 := testutils.ParseKubectlJSONResult(t, listConfigMap) + kubeCM := utils.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 deleted file mode 100644 index 3e455232df..0000000000 --- a/test/integration/testutils/json.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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{ - "E022[23] .* 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)) -} diff --git a/test/integration/testutils/retry.go b/test/integration/testutils/retry.go deleted file mode 100644 index c9fa684beb..0000000000 --- a/test/integration/testutils/retry.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2022-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 - -var ( - RetryableTransientErrors = map[string]string{ - // Error 409: unable to queue the operation - ".*Error 409.*unable to queue the operation": "Unable to queue operation.", - - // Error code 409 for concurrent policy changes. - ".*Error 409.*There were concurrent policy changes.*": "Concurrent policy changes.", - - // API Rate limit exceeded errors can be retried. - ".*rateLimitExceeded.*": "Rate limit exceeded.", - } -) diff --git a/test/integration/utils/utils.go b/test/integration/testutils/utils.go similarity index 79% rename from test/integration/utils/utils.go rename to test/integration/testutils/utils.go index 0640ce7273..1554678b91 100644 --- a/test/integration/utils/utils.go +++ b/test/integration/testutils/utils.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package utils +package testutils import ( "slices" @@ -23,12 +23,24 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" tfjson "github.com/hashicorp/terraform-json" "github.com/stretchr/testify/assert" - "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" +) + +var ( + RetryableTransientErrors = map[string]string{ + // Error 409: unable to queue the operation + ".*Error 409.*unable to queue the operation": "Unable to queue operation.", + + // Error code 409 for concurrent policy changes. + ".*Error 409.*There were concurrent policy changes.*": "Concurrent policy changes.", + + // API Rate limit exceeded errors can be retried. + ".*rateLimitExceeded.*": "Rate limit exceeded.", + } ) func GetTestProjectFromSetup(t *testing.T, idx int) string { setup := tft.NewTFBlueprintTest(t, - tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), + tft.WithRetryableTerraformErrors(RetryableTransientErrors, 3, 2*time.Minute), ) projectIDs := setup.GetTFSetupOutputListVal("project_ids") if len(projectIDs)-1 < idx {