Skip to content

Commit c9a373a

Browse files
authored
chore(CI): add new verify (#2156)
1 parent 5d1f7d4 commit c9a373a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/integration/sandbox_enabled/sandbox_enabled_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
2323
"github.com/stretchr/testify/assert"
2424
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
25+
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils"
2526
)
2627

2728
func TestSandboxEnabled(t *testing.T) {
@@ -32,6 +33,7 @@ func TestSandboxEnabled(t *testing.T) {
3233
bpt.DefineVerify(func(assert *assert.Assertions) {
3334
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token
3435
// bpt.DefaultVerify(assert)
36+
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources
3537

3638
projectId := bpt.GetStringOutput("project_id")
3739
location := bpt.GetStringOutput("location")

test/integration/utils/utils.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
package utils
1616

1717
import (
18+
"slices"
19+
"strings"
1820
"testing"
1921
"time"
2022

2123
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
24+
tfjson "github.com/hashicorp/terraform-json"
25+
"github.com/stretchr/testify/assert"
2226
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
2327
)
2428

@@ -32,3 +36,22 @@ func GetTestProjectFromSetup(t *testing.T, idx int) string {
3236
}
3337
return projectIDs[idx]
3438
}
39+
40+
// TGKEVerify asserts no resource changes exist after apply.
41+
func TGKEVerify(t *testing.T, b *tft.TFBlueprintTest, assert *assert.Assertions) {
42+
TGKEVerifyExemptResources(t, b, assert, []string{})
43+
}
44+
45+
// TGKEVerifyExemptResources asserts no resource changes exist after apply except exempt resources: e.g. google_container_cluster.primary
46+
func TGKEVerifyExemptResources(t *testing.T, b *tft.TFBlueprintTest, assert *assert.Assertions, verifyExemptResources []string) {
47+
_, ps := b.PlanAndShow()
48+
for _, r := range ps.ResourceChangesMap {
49+
if slices.ContainsFunc(verifyExemptResources, func(str string) bool {
50+
return strings.HasSuffix(r.Address, str)
51+
}) {
52+
t.Logf("Exempt plan address: %s", r.Address)
53+
continue
54+
}
55+
assert.Equal(tfjson.Actions{tfjson.ActionNoop}, r.Change.Actions, "Plan must be no-op for resource: %s", r.Address)
56+
}
57+
}

0 commit comments

Comments
 (0)