Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions tests/other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ func TestRunFSCloudExample(t *testing.T) {
*/
//ResourceGroup: resourceGroup,
TerraformVars: map[string]interface{}{
"access_tags": permanentResources["accessTags"],
"existing_kms_instance_guid": permanentResources["hpcs_south"],
"kms_key_crn": permanentResources["hpcs_south_root_key_crn"],
"rabbitmq_version": "3.13", // Always lock this test into the latest supported RabbitMQ version
"access_tags": permanentResources["accessTags"],
"kms_key_crn": permanentResources["hpcs_south_root_key_crn"],
"rabbitmq_version": "3.13", // Always lock this test into the latest supported RabbitMQ version
},
CloudInfoService: sharedInfoSvc,
})
Expand Down
73 changes: 63 additions & 10 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/cloudinfo"
Expand Down Expand Up @@ -173,15 +174,6 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
func TestRunStandardUpgradeSolution(t *testing.T) {
t.Parallel()

// Generate a 15 char long random string for the admin_pass
randomBytes := make([]byte, 13)
_, err := rand.Read(randomBytes)
if err != nil {
log.Fatal(err)
}
// add character prefix to avoid generated password beginning with special char and must have a number
randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]

options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
Testing: t,
TerraformDir: standardSolutionTerraformDir,
Expand All @@ -196,7 +188,7 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
"kms_endpoint_type": "public",
"provider_visibility": "public",
"resource_group_name": options.Prefix,
"admin_pass": randomPass,
"admin_pass": GetRandomAdminPassword(t),
}

output, err := options.RunTestUpgrade()
Expand All @@ -205,3 +197,64 @@ func TestRunStandardUpgradeSolution(t *testing.T) {
assert.NotNil(t, output, "Expected some output")
}
}

func TestPlanValidation(t *testing.T) {
t.Parallel()

options := &terraform.Options{
TerraformDir: "../" + standardSolutionTerraformDir,
Vars: map[string]interface{}{
"prefix": "validate-plan",
"region": "us-south",
"kms_endpoint_type": "public",
"provider_visibility": "public",
"resource_group_name": "validate-plan",
"admin_pass": GetRandomAdminPassword(t),
},
Upgrade: true,
}

_, initErr := terraform.InitE(t, options)
assert.Nil(t, initErr, "This should not have errored")

// Test the DA when using IBM owned encryption keys
var ibmOwnedEncrytionKeyTFVars = map[string]interface{}{
"use_default_backup_encryption_key": false,
"use_ibm_owned_encryption_key": true,
}

// Test the DA when using Default Backup Encryption Key and not IBM owned encryption keys
var notIbmOwnedEncrytionKeyTFVars = map[string]interface{}{
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
"use_default_backup_encryption_key": true,
"use_ibm_owned_encryption_key": false,
}

// Create a list (slice) of the maps
tfVarsList := []map[string]interface{}{
ibmOwnedEncrytionKeyTFVars,
notIbmOwnedEncrytionKeyTFVars,
}

// Iterate over the slice of maps
for _, tfVars := range tfVarsList {
// Iterate over the keys and values in each map
for key, value := range tfVars {
options.Vars[key] = value
}
output, err := terraform.PlanE(t, options)
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}
}

func GetRandomAdminPassword(t *testing.T) string {
// Generate a 15 char long random string for the admin_pass
randomBytes := make([]byte, 13)
_, randErr := rand.Read(randomBytes)
require.Nil(t, randErr) // do not proceed if we can't gen a random password

randomPass := "A1" + base64.URLEncoding.EncodeToString(randomBytes)[:13]

return randomPass
}