Skip to content

Commit

Permalink
test: acr tests refactor prototype (PSKD-1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Illiano committed Feb 26, 2025
1 parent 48180b1 commit 3eb73fc
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 174 deletions.
124 changes: 124 additions & 0 deletions test/acr_new_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

//const ACR_STATEFUL_SOURCE = "azurerm_container_registry.acr[0]"

// Verify Acr disabled stuff
func TestPlanAcrDisabledNew(t *testing.T) {
acrDisabledTests := map[string]testCase{
"acrDisabledTest": {
expected: "",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$}",
retriever: resourceRetrieverRequireNotExist,
},
}

variables := getDefaultPlanVars(t)
variables["create_container_registry"] = false
variables["container_registry_admin_enabled"] = true
plan, err := initPlanWithVariables(t, variables)
require.NotNil(t, plan)
require.NoError(t, err)

for name, tc := range acrDisabledTests {
t.Run(name, func(t *testing.T) {
runTest(t, tc, plan)
})
}
}

// Verify Acr standard stuff
func TestPlanACRStandardNew(t *testing.T) {
acrStandardTests := map[string]testCase{
"acrGeoRepsNotExistTest": {
expected: "[]",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.georeplications}",
},
//"nameTest": {
// expected: "terratestfyppteacr",
// resourceMapName: "azurerm_container_registry.acr[0]",
// attributeJsonPath: "{$.name}",
//},
"skuTest": {
expected: "Standard",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.sku}",
},
"adminEnabledTest": {
expected: "true",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.admin_enabled}",
},
}

variables := getDefaultPlanVars(t)
variables["create_container_registry"] = true
variables["container_registry_admin_enabled"] = true
variables["container_registry_sku"] = "Standard"
plan, err := initPlanWithVariables(t, variables)
require.NotNil(t, plan)
require.NoError(t, err)

for name, tc := range acrStandardTests {
t.Run(name, func(t *testing.T) {
runTest(t, tc, plan)
})
}
}

// Verify Acr premium stuff
func TestPlanACRPremiumNew(t *testing.T) {
acrPremiumTests := map[string]testCase{
"locationsTest": {
expected: "southeastus3 southeastus5",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.georeplications[*].location}",
},
//"nameTest": {
// expected: "terratestws5omyacr",
// resourceMapName: "azurerm_container_registry.acr[0]",
// attributeJsonPath: "{$.name}",
//},
"skuTest": {
expected: "Premium",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.sku}",
},
"adminEnabledTest": {
expected: "true",
resourceMapName: "azurerm_container_registry.acr[0]",
attributeJsonPath: "{$.admin_enabled}",
},
}

variables := getDefaultPlanVars(t)
variables["create_container_registry"] = true
variables["container_registry_admin_enabled"] = true
variables["container_registry_sku"] = "Premium"
variables["container_registry_geo_replica_locs"] = []string{"southeastus5", "southeastus3"}
plan, err := initPlanWithVariables(t, variables)
require.NotNil(t, plan)
require.NoError(t, err)

for name, tc := range acrPremiumTests {
t.Run(name, func(t *testing.T) {
runTest(t, tc, plan)
})
}
}

func resourceRetrieverRequireNotExist(t *testing.T, plan *terraform.PlanStruct, resourceMapName string,
attributeJsonPath string) (string, error) {
_, exists := plan.ResourcePlannedValuesMap[resourceMapName]
assert.False(t, exists, "Should not be present")
return "", nil
}
4 changes: 2 additions & 2 deletions test/acr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPlanACRStandard(t *testing.T) {
acrResource := plan.ResourcePlannedValuesMap[ACR_STATEFUL_SOURCE]
commonAssertions(t, variables, acrResource)

geoReplications, err := getJsonPathFromStateResource(acrResource, "{$.georeplications}")
geoReplications, err := getJsonPathFromStateResource(t, acrResource, "{$.georeplications}")
assert.NoError(t, err)
assert.Equal(t, "[]", geoReplications, "Geo-replications found when they should not be present")
}
Expand All @@ -58,7 +58,7 @@ func TestPlanACRPremium(t *testing.T) {
commonAssertions(t, variables, acrResource)

// Validate geo-replication locations
actualGeoReplications, err := getJsonPathFromStateResource(acrResource, "{$.georeplications[*].location}")
actualGeoReplications, err := getJsonPathFromStateResource(t, acrResource, "{$.georeplications[*].location}")
assert.NoError(t, err)
expectedGeoReplications := variables["container_registry_geo_replica_locs"].([]string)
assert.ElementsMatch(t, expectedGeoReplications, strings.Fields(actualGeoReplications), "Geo-replications do not match expected values")
Expand Down
2 changes: 1 addition & 1 deletion test/default_integration_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestDefaults(t *testing.T) {
}

func testSSHKey(t *testing.T, cluster *tfjson.StateResource) bool {
key, err := getJsonPathFromStateResource(cluster, "{$.linux_profile[0].ssh_key[0].key_data}")
key, err := getJsonPathFromStateResource(t, cluster, "{$.linux_profile[0].ssh_key[0].key_data}")
assert.NoError(t, err)
return key != ""
}
Expand Down
68 changes: 26 additions & 42 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
module test

go 1.22.4
go 1.23.0

toolchain go1.23.2

require (
github.com/gruntwork-io/terratest v0.48.2
github.com/hashicorp/terraform-json v0.23.0
github.com/stretchr/testify v1.10.0
k8s.io/client-go v0.28.4
k8s.io/client-go v0.32.2
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/azure-sdk-for-go v51.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3 v3.0.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.20 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.5 // indirect
Expand Down Expand Up @@ -68,23 +54,22 @@ require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand All @@ -93,7 +78,6 @@ require (
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
Expand All @@ -103,46 +87,46 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/pquerna/otp v1.4.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmccombs/hcl2json v0.6.4 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/urfave/cli v1.22.16 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.4 // indirect
k8s.io/apimachinery v0.28.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
k8s.io/api v0.32.2 // indirect
k8s.io/apimachinery v0.32.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 3eb73fc

Please sign in to comment.