Skip to content

Commit 57d286b

Browse files
jor2Jordan-Williams2
andauthored
test: add plan validation test (#321)
Co-authored-by: Jordan-Williams2 <[email protected]>
1 parent b8b6019 commit 57d286b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/pr_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"strings"
1414
"testing"
1515

16+
"github.com/gruntwork-io/terratest/modules/logger"
17+
"github.com/gruntwork-io/terratest/modules/terraform"
1618
"github.com/stretchr/testify/assert"
1719
"github.com/stretchr/testify/require"
1820
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/cloudinfo"
@@ -197,6 +199,63 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
197199
}
198200
}
199201

202+
func TestPlanValidation(t *testing.T) {
203+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
204+
Testing: t,
205+
TerraformDir: standardSolutionTerraformDir,
206+
Prefix: "validate-plan",
207+
ResourceGroup: resourceGroup,
208+
Region: "us-south", // skip VPC region picker
209+
})
210+
options.TestSetup()
211+
options.TerraformOptions.NoColor = true
212+
options.TerraformOptions.Logger = logger.Discard
213+
options.TerraformOptions.Vars = map[string]interface{}{
214+
"prefix": options.Prefix,
215+
"region": "us-south",
216+
"rabbitmq_version": "3.13",
217+
"provider_visibility": "public",
218+
"resource_group_name": options.Prefix,
219+
}
220+
221+
// Test the DA when using an existing KMS instance
222+
var standardSolutionWithExistingKms = map[string]interface{}{
223+
"access_tags": permanentResources["accessTags"],
224+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
225+
}
226+
227+
// Test the DA when using IBM owned encryption key
228+
var standardSolutionWithUseIbmOwnedEncKey = map[string]interface{}{
229+
"use_ibm_owned_encryption_key": true,
230+
}
231+
232+
// Create a map of the variables
233+
tfVarsMap := map[string]map[string]interface{}{
234+
"standardSolutionWithExistingKms": standardSolutionWithExistingKms,
235+
"standardSolutionWithUseIbmOwnedEncKey": standardSolutionWithUseIbmOwnedEncKey,
236+
}
237+
238+
_, initErr := terraform.InitE(t, options.TerraformOptions)
239+
if assert.Nil(t, initErr, "This should not have errored") {
240+
// Iterate over the slice of maps
241+
for name, tfVars := range tfVarsMap {
242+
t.Run(name, func(t *testing.T) {
243+
// Iterate over the keys and values in each map
244+
for key, value := range tfVars {
245+
options.TerraformOptions.Vars[key] = value
246+
}
247+
output, err := terraform.PlanE(t, options.TerraformOptions)
248+
assert.Nil(t, err, "This should not have errored")
249+
assert.NotNil(t, output, "Expected some output")
250+
// Delete the keys from the map
251+
for key := range tfVars {
252+
delete(options.TerraformOptions.Vars, key)
253+
}
254+
})
255+
}
256+
}
257+
}
258+
200259
func GetRandomAdminPassword(t *testing.T) string {
201260
// Generate a 15 char long random string for the admin_pass
202261
randomBytes := make([]byte, 13)

0 commit comments

Comments
 (0)