@@ -124,59 +124,89 @@ func TestRunStandardSolution(t *testing.T) {
124124 assert .NotNil (t , output , "Expected some output" )
125125}
126126
127- // Test the DA when using IBM owned encryption keys
128- func TestRunStandardSolutionIBMKeys (t * testing.T ) {
127+ func TestRunStandardUpgradeSolution (t * testing.T ) {
129128 t .Parallel ()
130129
131130 options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
132131 Testing : t ,
133132 TerraformDir : standardSolutionTerraformDir ,
134133 Region : "us-south" ,
135- Prefix : "postgres-icd-key " ,
134+ Prefix : "postgres-st-da-upg " ,
136135 ResourceGroup : resourceGroup ,
137136 })
138137
139138 options .TerraformVars = map [string ]interface {}{
140- "pg_version" : "16" ,
141- "provider_visibility" : "public" ,
142- "resource_group_name" : options .Prefix ,
143- "use_ibm_owned_encryption_key" : true ,
139+ "existing_kms_instance_crn" : permanentResources ["hpcs_south_crn" ],
140+ "kms_endpoint_type" : "public" ,
141+ "provider_visibility" : "public" ,
142+ "resource_group_name" : options .Prefix ,
143+ "admin_pass" : GetRandomAdminPassword (t ),
144144 }
145145
146- output , err := options .RunTestConsistency ()
147- assert .Nil (t , err , "This should not have errored" )
148- assert .NotNil (t , output , "Expected some output" )
146+ output , err := options .RunTestUpgrade ()
147+ if ! options .UpgradeTestSkipped {
148+ assert .Nil (t , err , "This should not have errored" )
149+ assert .NotNil (t , output , "Expected some output" )
150+ }
149151}
150152
151- func TestRunStandardUpgradeSolution (t * testing.T ) {
153+ func TestPlanValidation (t * testing.T ) {
152154 t .Parallel ()
153155
154- // Generate a 15 char long random string for the admin_pass.
155- randomBytes := make ([]byte , 13 )
156- _ , randErr := rand .Read (randomBytes )
157- require .Nil (t , randErr ) // do not proceed if we can't gen a random password
156+ options := & terraform.Options {
157+ TerraformDir : "../" + standardSolutionTerraformDir ,
158+ Vars : map [string ]interface {}{
159+ "prefix" : "validate-plan" ,
160+ "region" : "us-south" ,
161+ "kms_endpoint_type" : "public" ,
162+ "provider_visibility" : "public" ,
163+ "resource_group_name" : "validate-plan" ,
164+ "admin_pass" : GetRandomAdminPassword (t ),
165+ },
166+ Upgrade : true ,
167+ }
158168
159- randomPass := "A1" + base64 .URLEncoding .EncodeToString (randomBytes )[:13 ]
169+ _ , initErr := terraform .InitE (t , options )
170+ assert .Nil (t , initErr , "This should not have errored" )
160171
161- options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
162- Testing : t ,
163- TerraformDir : standardSolutionTerraformDir ,
164- Region : "us-south" ,
165- Prefix : "postgres-st-da-upg" ,
166- ResourceGroup : resourceGroup ,
167- })
172+ // Test the DA when using IBM owned encryption keys
173+ var ibmOwnedEncrytionKeyTFVars = map [string ]interface {}{
174+ "use_default_backup_encryption_key" : false ,
175+ "use_ibm_owned_encryption_key" : true ,
176+ }
168177
169- options .TerraformVars = map [string ]interface {}{
170- "existing_kms_instance_crn" : permanentResources ["hpcs_south_crn" ],
171- "kms_endpoint_type" : "public" ,
172- "provider_visibility" : "public" ,
173- "resource_group_name" : options .Prefix ,
174- "admin_pass" : randomPass ,
178+ // Test the DA when using Default Backup Encryption Key and not IBM owned encryption keys
179+ var notIbmOwnedEncrytionKeyTFVars = map [string ]interface {}{
180+ "existing_kms_instance_crn" : permanentResources ["hpcs_south_crn" ],
181+ "use_default_backup_encryption_key" : true ,
182+ "use_ibm_owned_encryption_key" : false ,
175183 }
176184
177- output , err := options .RunTestUpgrade ()
178- if ! options .UpgradeTestSkipped {
185+ // Create a list (slice) of the maps
186+ tfVarsList := []map [string ]interface {}{
187+ ibmOwnedEncrytionKeyTFVars ,
188+ notIbmOwnedEncrytionKeyTFVars ,
189+ }
190+
191+ // Iterate over the slice of maps
192+ for _ , tfVars := range tfVarsList {
193+ // Iterate over the keys and values in each map
194+ for key , value := range tfVars {
195+ options .Vars [key ] = value
196+ }
197+ output , err := terraform .PlanE (t , options )
179198 assert .Nil (t , err , "This should not have errored" )
180199 assert .NotNil (t , output , "Expected some output" )
181200 }
182201}
202+
203+ func GetRandomAdminPassword (t * testing.T ) string {
204+ // Generate a 15 char long random string for the admin_pass
205+ randomBytes := make ([]byte , 13 )
206+ _ , randErr := rand .Read (randomBytes )
207+ require .Nil (t , randErr ) // do not proceed if we can't gen a random password
208+
209+ randomPass := "A1" + base64 .URLEncoding .EncodeToString (randomBytes )[:13 ]
210+
211+ return randomPass
212+ }
0 commit comments