Skip to content

Commit

Permalink
chore: consolidate test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Nov 22, 2024
1 parent 367ef8e commit 234db37
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 79 deletions.
2 changes: 1 addition & 1 deletion test/integration/deploy_service/deploy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions test/integration/sandbox_enabled/sandbox_enabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion test/integration/simple_zonal/simple_zonal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

})
Expand Down
40 changes: 0 additions & 40 deletions test/integration/testutils/json.go

This file was deleted.

28 changes: 0 additions & 28 deletions test/integration/testutils/retry.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package utils
package testutils

import (
"slices"
Expand All @@ -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 {
Expand Down

0 comments on commit 234db37

Please sign in to comment.