@@ -124,59 +124,89 @@ func TestRunStandardSolution(t *testing.T) {
124
124
assert .NotNil (t , output , "Expected some output" )
125
125
}
126
126
127
- // Test the DA when using IBM owned encryption keys
128
- func TestRunStandardSolutionIBMKeys (t * testing.T ) {
127
+ func TestRunStandardUpgradeSolution (t * testing.T ) {
129
128
t .Parallel ()
130
129
131
130
options := testhelper .TestOptionsDefault (& testhelper.TestOptions {
132
131
Testing : t ,
133
132
TerraformDir : standardSolutionTerraformDir ,
134
133
Region : "us-south" ,
135
- Prefix : "postgres-icd-key " ,
134
+ Prefix : "postgres-st-da-upg " ,
136
135
ResourceGroup : resourceGroup ,
137
136
})
138
137
139
138
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 ),
144
144
}
145
145
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
+ }
149
151
}
150
152
151
- func TestRunStandardUpgradeSolution (t * testing.T ) {
153
+ func TestPlanValidation (t * testing.T ) {
152
154
t .Parallel ()
153
155
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
+ }
158
168
159
- randomPass := "A1" + base64 .URLEncoding .EncodeToString (randomBytes )[:13 ]
169
+ _ , initErr := terraform .InitE (t , options )
170
+ assert .Nil (t , initErr , "This should not have errored" )
160
171
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
+ }
168
177
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 ,
175
183
}
176
184
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 )
179
198
assert .Nil (t , err , "This should not have errored" )
180
199
assert .NotNil (t , output , "Expected some output" )
181
200
}
182
201
}
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