Skip to content

Commit fb700ad

Browse files
authored
test: da-upgrade-test (#891)
1 parent 602c936 commit fb700ad

File tree

2 files changed

+129
-18
lines changed

2 files changed

+129
-18
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-05-21T09:46:16Z",
6+
"generated_at": "2025-05-23T10:42:30Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -138,7 +138,7 @@
138138
"hashed_secret": "3e4bdbe0b80e63c22b178576e906810777387b50",
139139
"is_secret": false,
140140
"is_verified": false,
141-
"line_number": 237,
141+
"line_number": 225,
142142
"type": "Secret Keyword",
143143
"verified_result": null
144144
}

tests/pr_test.go

Lines changed: 127 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,6 @@ func TestRunReplicateExample(t *testing.T) {
219219
assert.NotNil(t, output, "Expected some output")
220220
}
221221

222-
func TestRunUpgradeExample(t *testing.T) {
223-
t.Parallel()
224-
225-
options := setupOptions(t, "cos-upgrade", advancedExampleTerraformDir)
226-
227-
output, err := options.RunTestUpgrade()
228-
if !options.UpgradeTestSkipped {
229-
assert.Nil(t, err, "This should not have errored")
230-
assert.NotNil(t, output, "Expected some output")
231-
}
232-
}
233-
234222
func getIAMBearerToken(apikey string) string {
235223
authEndpoint := "https://iam.cloud.ibm.com/identity/token"
236224
data := url.Values{}
@@ -327,8 +315,7 @@ func TestRunSolutionsInSchematics(t *testing.T) {
327315
instanceOptions.TerraformVars = []testschematic.TestSchematicTerraformVar{
328316
{Name: "ibmcloud_api_key", Value: instanceOptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
329317
{Name: "prefix", Value: instanceOptions.Prefix, DataType: "string"},
330-
{Name: "resource_group_name", Value: resourceGroup, DataType: "string"},
331-
{Name: "use_existing_resource_group", Value: "true", DataType: "bool"},
318+
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
332319
{Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"},
333320
{Name: "service_credential_secrets", Value: service_credential_secrets, DataType: "list(object{})"},
334321
}
@@ -361,7 +348,7 @@ func TestRunSolutionsInSchematics(t *testing.T) {
361348
regionaloptions.TerraformVars = []testschematic.TestSchematicTerraformVar{
362349
{Name: "ibmcloud_api_key", Value: regionaloptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
363350
{Name: "prefix", Value: regionaloptions.Prefix, DataType: "string"},
364-
{Name: "bucket_name", Value: fmt.Sprintf("%s-regional-bucket", prefix), DataType: "string"},
351+
{Name: "bucket_name", Value: "regional-bucket", DataType: "string"},
365352
{Name: "region", Value: region, DataType: "string"},
366353
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
367354
{Name: "existing_cos_instance_crn", Value: cos_instance_crn, DataType: "string"},
@@ -390,7 +377,7 @@ func TestRunSolutionsInSchematics(t *testing.T) {
390377
{Name: "ibmcloud_api_key", Value: regionaloptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
391378
{Name: "prefix", Value: crossregionaloptions.Prefix, DataType: "string"},
392379
{Name: "cross_region_location", Value: "us", DataType: "string"},
393-
{Name: "bucket_name", Value: fmt.Sprintf("%s-cross-region-bucket", prefix), DataType: "string"},
380+
{Name: "bucket_name", Value: "cross-regional-bucket", DataType: "string"},
394381
{Name: "existing_kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
395382
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
396383
{Name: "existing_cos_instance_crn", Value: cos_instance_crn, DataType: "string"},
@@ -404,3 +391,127 @@ func TestRunSolutionsInSchematics(t *testing.T) {
404391
instanceOptions.TestTearDown()
405392

406393
}
394+
395+
func TestRunDAUpgradeInSchematics(t *testing.T) {
396+
t.Parallel()
397+
398+
prefix := "cos-upg"
399+
400+
instanceOptions := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
401+
Testing: t,
402+
Region: region,
403+
Prefix: prefix,
404+
TarIncludePatterns: []string{
405+
"*.tf",
406+
"modules/buckets/*.tf",
407+
"modules/fscloud/*.tf",
408+
solutionInstanceDir + "/*.tf",
409+
},
410+
TemplateFolder: solutionInstanceDir,
411+
Tags: []string{"cos-upg"},
412+
DeleteWorkspaceOnFail: false,
413+
WaitJobCompleteMinutes: 120,
414+
CheckApplyResultForUpgrade: true,
415+
})
416+
417+
service_credential_secrets := []map[string]interface{}{
418+
{
419+
"secret_group_name": fmt.Sprintf("%s-secret-group", instanceOptions.Prefix),
420+
"service_credentials": []map[string]string{
421+
{
422+
"secret_name": fmt.Sprintf("%s-cred-manager", instanceOptions.Prefix),
423+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Manager",
424+
},
425+
{
426+
"secret_name": fmt.Sprintf("%s-cred-writer", instanceOptions.Prefix),
427+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
428+
},
429+
{
430+
"secret_name": fmt.Sprintf("%s-cred-object-writer", instanceOptions.Prefix),
431+
"service_credentials_source_service_role_crn": "crn:v1:bluemix:public:cloud-object-storage::::serviceRole:ObjectWriter",
432+
},
433+
},
434+
},
435+
}
436+
437+
instanceOptions.TerraformVars = []testschematic.TestSchematicTerraformVar{
438+
{Name: "ibmcloud_api_key", Value: instanceOptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
439+
{Name: "prefix", Value: instanceOptions.Prefix, DataType: "string"},
440+
{Name: "existing_resource_group_name", Value: resourceGroup, DataType: "string"},
441+
{Name: "existing_secrets_manager_instance_crn", Value: permanentResources["secretsManagerCRN"], DataType: "string"},
442+
{Name: "service_credential_secrets", Value: service_credential_secrets, DataType: "list(object{})"},
443+
}
444+
445+
instanceOptions.SkipTestTearDown = true
446+
err := instanceOptions.RunSchematicUpgradeTest()
447+
assert.Nil(t, err, "This should not have errored")
448+
449+
cos_instance_crn := instanceOptions.LastTestTerraformOutputs["cos_instance_crn"].(map[string]interface{})["value"].(string)
450+
451+
if assert.Nil(t, err, "This should not have errored") &&
452+
assert.NotNil(t, instanceOptions.LastTestTerraformOutputs, "Expected some Terraform outputs") {
453+
454+
regionaloptions := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
455+
Testing: t,
456+
Region: region,
457+
Prefix: prefix,
458+
TarIncludePatterns: []string{
459+
"*.tf",
460+
"modules/buckets/*.tf",
461+
"modules/fscloud/*.tf",
462+
solutionRegionalDir + "/*.tf",
463+
},
464+
TemplateFolder: solutionRegionalDir,
465+
Tags: []string{"cos-regional-bucket-upgrade-test"},
466+
DeleteWorkspaceOnFail: false,
467+
WaitJobCompleteMinutes: 120,
468+
CheckApplyResultForUpgrade: true,
469+
})
470+
471+
regionaloptions.TerraformVars = []testschematic.TestSchematicTerraformVar{
472+
{Name: "ibmcloud_api_key", Value: regionaloptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
473+
{Name: "prefix", Value: regionaloptions.Prefix, DataType: "string"},
474+
{Name: "bucket_name", Value: "regional-bucket", DataType: "string"},
475+
{Name: "region", Value: region, DataType: "string"},
476+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
477+
{Name: "existing_cos_instance_crn", Value: cos_instance_crn, DataType: "string"},
478+
}
479+
480+
regionalerr := regionaloptions.RunSchematicUpgradeTest()
481+
assert.Nil(t, regionalerr, "This should not have errored")
482+
483+
crossregionaloptions := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
484+
Testing: t,
485+
Region: region,
486+
Prefix: prefix,
487+
TarIncludePatterns: []string{
488+
"*.tf",
489+
"modules/buckets/*.tf",
490+
"modules/fscloud/*.tf",
491+
solutionCrossRegionDir + "/*.tf",
492+
},
493+
TemplateFolder: solutionCrossRegionDir,
494+
Tags: []string{"cos-cross-regional-bucket-upgrade-test"},
495+
DeleteWorkspaceOnFail: false,
496+
WaitJobCompleteMinutes: 120,
497+
CheckApplyResultForUpgrade: true,
498+
})
499+
500+
crossregionaloptions.TerraformVars = []testschematic.TestSchematicTerraformVar{
501+
{Name: "ibmcloud_api_key", Value: regionaloptions.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
502+
{Name: "prefix", Value: crossregionaloptions.Prefix, DataType: "string"},
503+
{Name: "cross_region_location", Value: "us", DataType: "string"},
504+
{Name: "bucket_name", Value: "cross-regional-bucket", DataType: "string"},
505+
{Name: "existing_kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
506+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
507+
{Name: "existing_cos_instance_crn", Value: cos_instance_crn, DataType: "string"},
508+
}
509+
510+
crossregionalerr := crossregionaloptions.RunSchematicUpgradeTest()
511+
assert.Nil(t, crossregionalerr, "This should not have errored")
512+
513+
}
514+
515+
instanceOptions.TestTearDown()
516+
517+
}

0 commit comments

Comments
 (0)