Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 52f5fea

Browse files
committed
Make tests work for both count and for_each
1 parent 34e02aa commit 52f5fea

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

test/e2e/terraform_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package e2e
22

33
import (
4+
"fmt"
45
"regexp"
56
"testing"
67

@@ -19,15 +20,22 @@ func TestExamples(t *testing.T) {
1920
"examples/private_link_service",
2021
}
2122
for _, example := range examples {
22-
t.Run(example, func(t *testing.T) {
23-
testExample(t, example)
23+
t.Run(fmt.Sprintf("%s_for_each", example), func(t *testing.T) {
24+
testExample(t, example, true)
25+
})
26+
t.Run(fmt.Sprintf("%s_count", example), func(t *testing.T) {
27+
testExample(t, example, false)
2428
})
2529
}
2630
}
2731

28-
func testExample(t *testing.T, exampleRelativePath string) {
32+
func testExample(t *testing.T, exampleRelativePath string, useForEach bool) {
33+
vars := map[string]interface{}{
34+
"use_for_each": useForEach,
35+
}
2936
test_helper.RunE2ETest(t, "../../", exampleRelativePath, terraform.Options{
3037
Upgrade: true,
38+
Vars: vars,
3139
}, func(t *testing.T, output test_helper.TerraformOutput) {
3240
vnetId, ok := output["test_vnet_id"].(string)
3341
assert.True(t, ok)

test/upgrade/upgrade_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package upgrade
22

33
import (
4+
"fmt"
45
"testing"
56

67
test_helper "github.com/Azure/terraform-module-test-helper"
@@ -17,13 +18,16 @@ func TestExamples(t *testing.T) {
1718
"examples/private_link_service",
1819
}
1920
for _, example := range examples {
20-
t.Run(example, func(t *testing.T) {
21-
testExample(t, example)
21+
t.Run(fmt.Sprintf("%s_for_each", example), func(t *testing.T) {
22+
testExample(t, example, true)
23+
})
24+
t.Run(fmt.Sprintf("%s_count", example), func(t *testing.T) {
25+
testExample(t, example, false)
2226
})
2327
}
2428
}
2529

26-
func testExample(t *testing.T, exampleRelativePath string) {
30+
func testExample(t *testing.T, exampleRelativePath string, useForEach bool) {
2731
currentRoot, err := test_helper.GetCurrentModuleRootPath()
2832
if err != nil {
2933
t.FailNow()
@@ -32,7 +36,11 @@ func testExample(t *testing.T, exampleRelativePath string) {
3236
if err != nil {
3337
t.FailNow()
3438
}
39+
vars := map[string]interface{}{
40+
"use_for_each": useForEach,
41+
}
3542
test_helper.ModuleUpgradeTest(t, "Azure", "terraform-azurerm-vnet", exampleRelativePath, currentRoot, terraform.Options{
3643
Upgrade: true,
44+
Vars: vars,
3745
}, currentMajorVersion)
3846
}

0 commit comments

Comments
 (0)