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

Commit

Permalink
Make tests work for both count and for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Dec 27, 2022
1 parent b2876f7 commit f5ffaf2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions test/e2e/terraform_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"fmt"
"regexp"
"testing"

Expand All @@ -19,15 +20,22 @@ func TestExamples(t *testing.T) {
"examples/private_link_service",
}
for _, example := range examples {
t.Run(example, func(t *testing.T) {
testExample(t, example)
t.Run(fmt.Sprintf("%s_for_each", example), func(t *testing.T) {
testExample(t, example, true)
})
t.Run(fmt.Sprintf("%s_count", example), func(t *testing.T) {
testExample(t, example, false)
})
}
}

func testExample(t *testing.T, exampleRelativePath string) {
func testExample(t *testing.T, exampleRelativePath string, useForEach bool) {
vars := map[string]interface{}{
"use_for_each": useForEach,
}
test_helper.RunE2ETest(t, "../../", exampleRelativePath, terraform.Options{
Upgrade: true,
Vars: vars,
}, func(t *testing.T, output test_helper.TerraformOutput) {
vnetId, ok := output["test_vnet_id"].(string)
assert.True(t, ok)
Expand Down
14 changes: 11 additions & 3 deletions test/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package upgrade

import (
"fmt"
"testing"

test_helper "github.com/Azure/terraform-module-test-helper"
Expand All @@ -17,13 +18,16 @@ func TestExamples(t *testing.T) {
"examples/private_link_service",
}
for _, example := range examples {
t.Run(example, func(t *testing.T) {
testExample(t, example)
t.Run(fmt.Sprintf("%s_for_each", example), func(t *testing.T) {
testExample(t, example, true)
})
t.Run(fmt.Sprintf("%s_count", example), func(t *testing.T) {
testExample(t, example, false)
})
}
}

func testExample(t *testing.T, exampleRelativePath string) {
func testExample(t *testing.T, exampleRelativePath string, useForEach bool) {
currentRoot, err := test_helper.GetCurrentModuleRootPath()
if err != nil {
t.FailNow()
Expand All @@ -32,7 +36,11 @@ func testExample(t *testing.T, exampleRelativePath string) {
if err != nil {
t.FailNow()
}
vars := map[string]interface{}{
"use_for_each": useForEach,
}
test_helper.ModuleUpgradeTest(t, "Azure", "terraform-azurerm-vnet", exampleRelativePath, currentRoot, terraform.Options{
Upgrade: true,
Vars: vars,
}, currentMajorVersion)
}

0 comments on commit f5ffaf2

Please sign in to comment.