-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrating test Framework for 3 test cases (#1489)
* Migrating Test Framework for 3test cases * Correcting Build File * Correcting Build File * Correcting Build File * Modifying Files based on Recommendations * Correcting JSON path * Modifying the path for networkconfig * Changing Sanitizer Order to remove Service Account * Modifying the peering name assert logic * UnSetting ProjectID to skip ProjectID Sanitiser * Removing Default Verify in Testing due to issue 1478 Co-authored-by: Akshay Bathija <[email protected]>
- Loading branch information
1 parent
363c4b5
commit 66fc20e
Showing
24 changed files
with
2,358 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2022 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 beta_cluster | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"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/stretchr/testify/assert" | ||
) | ||
|
||
func TestBetaCluster(t *testing.T) { | ||
gke := tft.NewTFBlueprintTest(t) | ||
|
||
gke.DefineVerify(func(assert *assert.Assertions) { | ||
// Commenting Default Verify due to issue 1478 for location Policy | ||
// gke.DefaultVerify(assert) //disables no changes | ||
|
||
projectId := gke.GetStringOutput("project_id") | ||
location := gke.GetStringOutput("location") | ||
clusterName := gke.GetStringOutput("cluster_name") | ||
serviceAccount := gke.GetStringOutput("service_account") | ||
gcloud.Runf(t, "config set project %s", projectId) | ||
op := gcloud.Runf(t, "beta container clusters describe %s --zone %s --project %s", clusterName, location, projectId) | ||
// save output as goldenfile | ||
g := golden.NewOrUpdate(t, op.String(), | ||
golden.WithSanitizer(golden.StringSanitizer(serviceAccount, "SERVICE_ACCOUNT")), | ||
golden.WithSanitizer(golden.StringSanitizer(projectId, "PROJECT_ID")), | ||
golden.WithSanitizer(golden.StringSanitizer(clusterName, "CLUSTER_NAME")), | ||
) | ||
// assert json paths against goldenfile data | ||
validateJSONPaths := []string{ | ||
"status", | ||
"location", | ||
"locations", | ||
"privateClusterConfig.enablePrivateEndpoint", | ||
"networkConfig.datapathProvider", | ||
"podSecurityPolicyConfig.enabled", | ||
"databaseEncryption.state", | ||
"identityServiceConfig.enabled", | ||
"addonsConfig", | ||
"networkConfig.datapathProvider", | ||
"binaryAuthorization", | ||
"podSecurityPolicyConfig", | ||
"databaseEncryption.state", | ||
"loggingConfig", | ||
"monitoringConfig", | ||
} | ||
for _, pth := range validateJSONPaths { | ||
g.JSONEq(assert, op, pth) | ||
} | ||
for _, np := range op.Get("nodePools").Array() { | ||
npName := np.Get("name").String() | ||
// sanitze current nodepool data | ||
np = g.GetSanitizedJSON(np) | ||
// retrive matching nodepool data from goldenfile | ||
gNp := utils.GetFirstMatchResult(t, g.GetJSON().Get("nodePools").Array(), "name", npName) | ||
switch npName { | ||
case "default-pool": | ||
assert.False(np.Get("initialNodeCount").Exists(), "has no initial node count") | ||
assert.False(np.Get("autoscaling").Exists(), "does not have autoscaling enabled") | ||
case "default-node-pool": | ||
assert.JSONEq(gNp.Get("config").String(), np.Get("config").String()) | ||
assert.JSONEq(gNp.Get("autoscaling").String(), np.Get("autoscaling").String()) | ||
assert.JSONEq(gNp.Get("management").String(), np.Get("management").String()) | ||
} | ||
} | ||
|
||
// verify SA | ||
op = gcloud.Runf(t, "iam service-accounts describe %s --project %s", serviceAccount, projectId) | ||
assert.Equal(fmt.Sprintf("Terraform-managed service account for cluster %s", clusterName), op.Get("displayName").String(), "has the correct displayname") | ||
|
||
}) | ||
gke.Test() | ||
} |
Oops, something went wrong.