Skip to content

Commit 23db3af

Browse files
committed
add v4 examples to acc tests
1 parent a1b217b commit 23db3af

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

test/e2e/terraform_aks_test.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"path/filepath"
78
"regexp"
89
"strings"
910
"testing"
1011
"time"
1112

12-
"github.com/hashicorp/go-retryablehttp"
13-
14-
"github.com/stretchr/testify/require"
15-
1613
test_helper "github.com/Azure/terraform-module-test-helper"
1714
"github.com/gruntwork-io/terratest/modules/terraform"
15+
"github.com/hashicorp/go-retryablehttp"
1816
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
1918
)
2019

2120
func TestExamplesStartup(t *testing.T) {
@@ -178,6 +177,41 @@ func TestExamples_applicationGatewayIngress(t *testing.T) {
178177
}
179178
}
180179

180+
func TestExamplesForV4(t *testing.T) {
181+
managedIdentityId := os.Getenv("MSI_ID")
182+
if managedIdentityId != "" {
183+
t.Setenv("TF_VAR_managed_identity_principal_id", managedIdentityId)
184+
}
185+
tmp, err := os.MkdirTemp("", "")
186+
require.NoError(t, err)
187+
defer func() {
188+
_ = os.RemoveAll(tmp)
189+
}()
190+
tfvars := filepath.Join(tmp, "terraform.tfvars")
191+
require.NoError(t, os.WriteFile(tfvars, []byte(`
192+
client_id = ""
193+
client_secret = ""
194+
`), 0o644))
195+
t.Setenv("TF_VAR_client_id", "")
196+
t.Setenv("TF_VAR_client_secret", "")
197+
examples, err := os.ReadDir("../../examples")
198+
require.NoError(t, err)
199+
for _, example := range examples {
200+
if !example.IsDir() {
201+
continue
202+
}
203+
if !strings.HasSuffix(example.Name(), "_v4") {
204+
continue
205+
}
206+
t.Run(example.Name(), func(t *testing.T) {
207+
test_helper.RunE2ETest(t, fmt.Sprintf("../../"), fmt.Sprintf("examples/%s", example.Name()), terraform.Options{
208+
Upgrade: true,
209+
VarFiles: []string{tfvars},
210+
}, nil)
211+
})
212+
}
213+
}
214+
181215
func getHTML(url string) (string, error) {
182216
client := retryablehttp.NewClient()
183217
client.RetryMax = 10

test/upgrade/upgrade_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package upgrade
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
7+
"strings"
68
"testing"
79
"time"
810

11+
"github.com/stretchr/testify/require"
12+
913
test_helper "github.com/Azure/terraform-module-test-helper"
1014
"github.com/gruntwork-io/terratest/modules/terraform"
1115
)
@@ -148,3 +152,45 @@ func TestExampleUpgrade_applicationGw(t *testing.T) {
148152
})
149153
}
150154
}
155+
156+
func TestExamplesForV4(t *testing.T) {
157+
managedIdentityId := os.Getenv("MSI_ID")
158+
if managedIdentityId != "" {
159+
t.Setenv("TF_VAR_managed_identity_principal_id", managedIdentityId)
160+
}
161+
tmp, err := os.MkdirTemp("", "")
162+
require.NoError(t, err)
163+
defer func() {
164+
_ = os.RemoveAll(tmp)
165+
}()
166+
tfvars := filepath.Join(tmp, "terraform.tfvars")
167+
require.NoError(t, os.WriteFile(tfvars, []byte(`
168+
client_id = ""
169+
client_secret = ""
170+
`), 0o644))
171+
t.Setenv("TF_VAR_client_id", "")
172+
t.Setenv("TF_VAR_client_secret", "")
173+
examples, err := os.ReadDir("../../examples")
174+
require.NoError(t, err)
175+
currentRoot, err := test_helper.GetCurrentModuleRootPath()
176+
if err != nil {
177+
t.FailNow()
178+
}
179+
currentMajorVersion, err := test_helper.GetCurrentMajorVersionFromEnv()
180+
if err != nil {
181+
t.FailNow()
182+
}
183+
for _, example := range examples {
184+
if !example.IsDir() {
185+
continue
186+
}
187+
if strings.HasSuffix(example.Name(), "_v4") {
188+
continue
189+
}
190+
t.Run(example.Name(), func(t *testing.T) {
191+
test_helper.ModuleUpgradeTest(t, "Azure", "terraform-azurerm-aks", fmt.Sprintf("examples/%s", example.Name()), currentRoot, terraform.Options{
192+
VarFiles: []string{tfvars},
193+
}, currentMajorVersion)
194+
})
195+
}
196+
}

0 commit comments

Comments
 (0)