Skip to content

Commit 5a10fd1

Browse files
authored
test: add plan test to suite (#409)
1 parent 51ebb62 commit 5a10fd1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/pr_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
112112
{Name: "enable_kibana_dashboard", Value: true, DataType: "bool"},
113113
{Name: "provider_visibility", Value: "private", DataType: "string"},
114114
{Name: "prefix", Value: options.Prefix, DataType: "string"},
115+
{Name: "admin_pass", Value: GetRandomAdminPassword(t), DataType: "string"},
115116
}
116117
err := options.RunSchematicTest()
117118
assert.Nil(t, err, "This should not have errored")
@@ -251,6 +252,72 @@ func TestRunStandardSolutionIBMKeys(t *testing.T) {
251252
assert.NotNil(t, output, "Expected some output")
252253
}
253254

255+
func TestPlanValidation(t *testing.T) {
256+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
257+
Testing: t,
258+
TerraformDir: standardSolutionTerraformDir,
259+
Prefix: "validate-plan",
260+
ResourceGroup: resourceGroup,
261+
Region: "us-south", // skip VPC region picker
262+
})
263+
options.TestSetup()
264+
options.TerraformOptions.NoColor = true
265+
options.TerraformOptions.Logger = logger.Discard
266+
options.TerraformOptions.Vars = map[string]interface{}{
267+
"prefix": options.Prefix,
268+
"region": "us-south",
269+
"elasticsearch_version": "8.10",
270+
"provider_visibility": "public",
271+
"resource_group_name": options.Prefix,
272+
}
273+
274+
// Test the DA when using Elser model
275+
var standardSolutionWithElserModelVars = map[string]interface{}{
276+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
277+
"enable_elser_model": true,
278+
"plan": "platinum",
279+
}
280+
281+
// Test the DA when using Kibana dashboard and existing KMS instance
282+
var standardSolutionWithKibanaDashboardVars = map[string]interface{}{
283+
"enable_kibana_dashboard": true,
284+
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
285+
"plan": "enterprise",
286+
}
287+
288+
// Test the DA when using IBM owned encryption key
289+
var standardSolutionWithUseIbmOwnedEncKey = map[string]interface{}{
290+
"use_ibm_owned_encryption_key": true,
291+
}
292+
293+
// Create a map of the variables
294+
tfVarsMap := map[string]map[string]interface{}{
295+
"standardSolutionWithElserModelVars": standardSolutionWithElserModelVars,
296+
"standardSolutionWithKibanaDashboardVars": standardSolutionWithKibanaDashboardVars,
297+
"standardSolutionWithUseIbmOwnedEncKey": standardSolutionWithUseIbmOwnedEncKey,
298+
}
299+
300+
_, initErr := terraform.InitE(t, options.TerraformOptions)
301+
if assert.Nil(t, initErr, "This should not have errored") {
302+
// Iterate over the slice of maps
303+
for name, tfVars := range tfVarsMap {
304+
t.Run(name, func(t *testing.T) {
305+
// Iterate over the keys and values in each map
306+
for key, value := range tfVars {
307+
options.TerraformOptions.Vars[key] = value
308+
}
309+
output, err := terraform.PlanE(t, options.TerraformOptions)
310+
assert.Nil(t, err, "This should not have errored")
311+
assert.NotNil(t, output, "Expected some output")
312+
// Delete the keys from the map
313+
for key := range tfVars {
314+
delete(options.TerraformOptions.Vars, key)
315+
}
316+
})
317+
}
318+
}
319+
}
320+
254321
func GetRandomAdminPassword(t *testing.T) string {
255322
// Generate a 15 char long random string for the admin_pass
256323
randomBytes := make([]byte, 13)

0 commit comments

Comments
 (0)