|
| 1 | +// Copyright 2024-2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +package node_pool |
| 15 | + |
| 16 | +import ( |
| 17 | + "fmt" |
| 18 | + "testing" |
| 19 | + "time" |
| 20 | + |
| 21 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/cai" |
| 22 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden" |
| 23 | + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | + "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils" |
| 26 | +) |
| 27 | + |
| 28 | +func TestSimpleRegionalWithGatewayAPI(t *testing.T) { |
| 29 | + bpt := tft.NewTFBlueprintTest(t, |
| 30 | + tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute), |
| 31 | + ) |
| 32 | + |
| 33 | + bpt.DefineVerify(func(assert *assert.Assertions) { |
| 34 | + // Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token |
| 35 | + // bpt.DefaultVerify(assert) |
| 36 | + testutils.TGKEVerify(t, bpt, assert) // Verify Resources |
| 37 | + |
| 38 | + projectId := bpt.GetStringOutput("project_id") |
| 39 | + location := bpt.GetStringOutput("location") |
| 40 | + clusterName := bpt.GetStringOutput("cluster_name") |
| 41 | + randomString := bpt.GetStringOutput("random_string") |
| 42 | + kubernetesEndpoint := bpt.GetStringOutput("kubernetes_endpoint") |
| 43 | + nodeServiceAccount := bpt.GetStringOutput("compute_engine_service_account") |
| 44 | + |
| 45 | + // Retrieve Project CAI |
| 46 | + projectCAI := cai.GetProjectResources(t, projectId, cai.WithAssetTypes([]string{"container.googleapis.com/Cluster"})) |
| 47 | + |
| 48 | + // Retrieve Cluster from CAI |
| 49 | + // Equivalent gcloud describe command (classic) |
| 50 | + // cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId) |
| 51 | + clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName) |
| 52 | + cluster := projectCAI.Get("#(name=\"" + clusterResourceName + "\").resource.data") |
| 53 | + |
| 54 | + // Setup golden image with sanitizers |
| 55 | + g := golden.NewOrUpdate(t, cluster.String(), |
| 56 | + golden.WithSanitizer(golden.StringSanitizer(nodeServiceAccount, "NODE_SERVICE_ACCOUNT")), |
| 57 | + golden.WithSanitizer(golden.StringSanitizer(projectId, "PROJECT_ID")), |
| 58 | + golden.WithSanitizer(golden.StringSanitizer(randomString, "RANDOM_STRING")), |
| 59 | + golden.WithSanitizer(golden.StringSanitizer(kubernetesEndpoint, "KUBERNETES_ENDPOINT")), |
| 60 | + ) |
| 61 | + |
| 62 | + // Cluster Assertions |
| 63 | + testutils.TGKEAssertGolden(assert, g, &cluster, []string{"default-pool"}, []string{"monitoringConfig.componentConfig.enableComponents"}) // TODO: enableComponents is UL |
| 64 | + }) |
| 65 | + bpt.Test() |
| 66 | +} |
0 commit comments