@@ -39,6 +39,9 @@ const service_endpoints = "private"
3939var sharedInfoSvc * cloudinfo.CloudInfoService
4040var permanentResources map [string ]interface {}
4141
42+ // Turn on Schematics tests, which can also skip the normal tests for same pattern
43+ var enableSchematicsTests bool
44+
4245// TestMain will be run before any parallel tests, used to set up a shared InfoService object to track region usage
4346// for multiple tests
4447func TestMain (m * testing.M ) {
@@ -50,6 +53,10 @@ func TestMain(m *testing.M) {
5053 log .Fatal (err )
5154 }
5255
56+ // ENABLE SCHEMATICS TESTS
57+ // To enable Schematics tests, and skip terratest for patterns, set boolean to true
58+ enableSchematicsTests = false
59+
5360 os .Exit (m .Run ())
5461}
5562
@@ -74,6 +81,10 @@ func setupOptionsQuickStartPattern(t *testing.T, prefix string, dir string) *tes
7481 "ssh_key" : sshPublicKey ,
7582 },
7683 CloudInfoService : sharedInfoSvc ,
84+ ImplicitRequired : true ,
85+ ImplicitDestroy : []string {
86+ "module.landing_zone.module.landing_zone.ibm_resource_group.resource_groups" ,
87+ },
7788 })
7889
7990 return options
@@ -120,6 +131,19 @@ func walk(r *tarIncludePatterns, s string, d fs.DirEntry, err error) error {
120131 return nil
121132}
122133
134+ func TestRunQuickStartPattern (t * testing.T ) {
135+ t .Parallel ()
136+ if enableSchematicsTests {
137+ t .Skip ("Skipping terratest for Quickstart Pattern, running Schematics test instead" )
138+ }
139+
140+ options := setupOptionsQuickStartPattern (t , "vsi-qs" , quickStartPatternTerraformDir )
141+
142+ output , err := options .RunTestConsistency ()
143+ assert .Nil (t , err , "This should not have errored" )
144+ assert .NotNil (t , output , "Expected some output" )
145+ }
146+
123147func TestRunUpgradeQuickStartPattern (t * testing.T ) {
124148 t .Parallel ()
125149
@@ -140,6 +164,10 @@ func setupOptionsRoksPattern(t *testing.T, prefix string) *testhelper.TestOption
140164 Prefix : prefix ,
141165 ResourceGroup : resourceGroup ,
142166 CloudInfoService : sharedInfoSvc ,
167+ ImplicitRequired : true ,
168+ ImplicitDestroy : []string {
169+ "module.roks_landing_zone.module.landing_zone.ibm_resource_group.resource_groups" ,
170+ },
143171 })
144172
145173 options .TerraformVars = map [string ]interface {}{
@@ -151,6 +179,19 @@ func setupOptionsRoksPattern(t *testing.T, prefix string) *testhelper.TestOption
151179 return options
152180}
153181
182+ func TestRunRoksPattern (t * testing.T ) {
183+ t .Parallel ()
184+ if enableSchematicsTests {
185+ t .Skip ("Skipping terratest for ROKS Pattern, running Schematics test instead" )
186+ }
187+
188+ options := setupOptionsRoksPattern (t , "ocp" )
189+
190+ output , err := options .RunTestConsistency ()
191+ assert .Nil (t , err , "This should not have errored" )
192+ assert .NotNil (t , output , "Expected some output" )
193+ }
194+
154195func TestRunUpgradeRoksPattern (t * testing.T ) {
155196 t .Parallel ()
156197
@@ -173,6 +214,10 @@ func setupOptionsVsiPattern(t *testing.T, prefix string) *testhelper.TestOptions
173214 Prefix : prefix ,
174215 ResourceGroup : resourceGroup ,
175216 CloudInfoService : sharedInfoSvc ,
217+ ImplicitRequired : true ,
218+ ImplicitDestroy : []string {
219+ "module.vsi_landing_zone.module.landing_zone.ibm_resource_group.resource_groups" ,
220+ },
176221 })
177222
178223 options .TerraformVars = map [string ]interface {}{
@@ -186,6 +231,19 @@ func setupOptionsVsiPattern(t *testing.T, prefix string) *testhelper.TestOptions
186231 return options
187232}
188233
234+ func TestRunVSIPattern (t * testing.T ) {
235+ t .Parallel ()
236+ if enableSchematicsTests {
237+ t .Skip ("Skipping terratest for VSI Pattern, running Schematics test instead" )
238+ }
239+
240+ options := setupOptionsVsiPattern (t , "vsi" )
241+
242+ output , err := options .RunTestConsistency ()
243+ assert .Nil (t , err , "This should not have errored" )
244+ assert .NotNil (t , output , "Expected some output" )
245+ }
246+
189247func TestRunUpgradeVsiPattern (t * testing.T ) {
190248 t .Parallel ()
191249
@@ -206,6 +264,10 @@ func setupOptionsVpcPattern(t *testing.T, prefix string) *testhelper.TestOptions
206264 Prefix : prefix ,
207265 ResourceGroup : resourceGroup ,
208266 CloudInfoService : sharedInfoSvc ,
267+ ImplicitRequired : true ,
268+ ImplicitDestroy : []string {
269+ "module.vpc_landing_zone.module.landing_zone.ibm_resource_group.resource_groups" ,
270+ },
209271 })
210272
211273 options .TerraformVars = map [string ]interface {}{
@@ -218,6 +280,19 @@ func setupOptionsVpcPattern(t *testing.T, prefix string) *testhelper.TestOptions
218280 return options
219281}
220282
283+ func TestRunVpcPattern (t * testing.T ) {
284+ t .Parallel ()
285+ if enableSchematicsTests {
286+ t .Skip ("Skipping terratest for VPC Pattern, running Schematics test instead" )
287+ }
288+
289+ options := setupOptionsVpcPattern (t , "vpc" )
290+
291+ output , err := options .RunTestConsistency ()
292+ assert .Nil (t , err , "This should not have errored" )
293+ assert .NotNil (t , output , "Expected some output" )
294+ }
295+
221296func TestRunUpgradeVpcPattern (t * testing.T ) {
222297 t .Parallel ()
223298
@@ -298,78 +373,6 @@ func setupOptionsSchematics(t *testing.T, prefix string, dir string) *testschema
298373 return options
299374}
300375
301- func TestRunVSIQuickStartPatternSchematics (t * testing.T ) {
302- t .Parallel ()
303-
304- options := setupOptionsSchematics (t , "qs-sc" , quickStartPatternTerraformDir )
305-
306- options .TerraformVars = []testschematic.TestSchematicTerraformVar {
307- {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
308- {Name : "region" , Value : options .Region , DataType : "string" },
309- {Name : "prefix" , Value : options .Prefix , DataType : "string" },
310- {Name : "ssh_key" , Value : sshPublicKey (t ), DataType : "string" },
311- {Name : "service_endpoints" , Value : "private" , DataType : "string" },
312- }
313-
314- err := options .RunSchematicTest ()
315- assert .NoError (t , err , "Schematic Test had unexpected error" )
316- }
317-
318- func TestRunVSIPatternSchematics (t * testing.T ) {
319- t .Parallel ()
320-
321- options := setupOptionsSchematics (t , "vsi-sc" , vsiPatternTerraformDir )
322-
323- options .TerraformVars = []testschematic.TestSchematicTerraformVar {
324- {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
325- {Name : "region" , Value : options .Region , DataType : "string" },
326- {Name : "prefix" , Value : options .Prefix , DataType : "string" },
327- {Name : "ssh_public_key" , Value : sshPublicKey (t ), DataType : "string" },
328- {Name : "add_atracker_route" , Value : add_atracker_route , DataType : "bool" },
329- {Name : "service_endpoints" , Value : "private" , DataType : "string" },
330- }
331-
332- err := options .RunSchematicTest ()
333- assert .NoError (t , err , "Schematic Test had unexpected error" )
334- }
335-
336- func TestRunRoksPatternSchematics (t * testing.T ) {
337- t .Parallel ()
338-
339- options := setupOptionsSchematics (t , "ocp-sc" , roksPatternTerraformDir )
340-
341- options .WaitJobCompleteMinutes = 120
342-
343- options .TerraformVars = []testschematic.TestSchematicTerraformVar {
344- {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
345- {Name : "region" , Value : options .Region , DataType : "string" },
346- {Name : "prefix" , Value : options .Prefix , DataType : "string" },
347- {Name : "tags" , Value : options .Tags , DataType : "list(string)" },
348- {Name : "service_endpoints" , Value : "private" , DataType : "string" },
349- }
350-
351- err := options .RunSchematicTest ()
352- assert .NoError (t , err , "Schematic Test had unexpected error" )
353- }
354-
355- func TestRunVPCPatternSchematics (t * testing.T ) {
356- t .Parallel ()
357-
358- options := setupOptionsSchematics (t , "vpc-sc" , vpcPatternTerraformDir )
359-
360- options .TerraformVars = []testschematic.TestSchematicTerraformVar {
361- {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
362- {Name : "region" , Value : options .Region , DataType : "string" },
363- {Name : "prefix" , Value : options .Prefix , DataType : "string" },
364- {Name : "tags" , Value : options .Tags , DataType : "list(string)" },
365- {Name : "add_atracker_route" , Value : add_atracker_route , DataType : "bool" },
366- {Name : "service_endpoints" , Value : "private" , DataType : "string" },
367- }
368-
369- err := options .RunSchematicTest ()
370- assert .NoError (t , err , "Schematic Test had unexpected error" )
371- }
372-
373376func TestRunVsiExtention (t * testing.T ) {
374377 t .Parallel ()
375378
@@ -475,8 +478,101 @@ func TestRunVsiExtention(t *testing.T) {
475478 fmt .Println ("Terratest failed. Debug the test and delete resources manually." )
476479 } else {
477480 logger .Log (t , "START: Destroy (existing resources)" )
481+ // ignore resource groups when destroying
482+ terraform .RunTerraformCommand (t , existingTerraformOptions , "state" , "rm" , "module.vpc_landing_zone.module.landing_zone.ibm_resource_group.resource_groups" )
478483 terraform .Destroy (t , existingTerraformOptions )
479484 terraform .WorkspaceDelete (t , existingTerraformOptions , prefix )
480485 logger .Log (t , "END: Destroy (existing resources)" )
481486 }
482487}
488+
489+ /***************************************************************************
490+ SCHEMATICS TESTS
491+ These schematics tests will only be run if the "RUN_SCHEMATICS_TESTS"
492+ environment variable is set to "true" or "yes".
493+ If not set, the normal terratest will be run for the patterns.
494+ ****************************************************************************/
495+
496+ func TestRunVSIQuickStartPatternSchematics (t * testing.T ) {
497+ t .Parallel ()
498+ if ! enableSchematicsTests {
499+ t .Skip ("Skipping Schematics Test for QuickStart Pattern, running terratest instead" )
500+ }
501+
502+ options := setupOptionsSchematics (t , "qs-sc" , quickStartPatternTerraformDir )
503+
504+ options .TerraformVars = []testschematic.TestSchematicTerraformVar {
505+ {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
506+ {Name : "region" , Value : options .Region , DataType : "string" },
507+ {Name : "prefix" , Value : options .Prefix , DataType : "string" },
508+ {Name : "ssh_key" , Value : sshPublicKey (t ), DataType : "string" },
509+ {Name : "service_endpoints" , Value : "private" , DataType : "string" },
510+ }
511+
512+ err := options .RunSchematicTest ()
513+ assert .NoError (t , err , "Schematic Test had unexpected error" )
514+ }
515+
516+ func TestRunVSIPatternSchematics (t * testing.T ) {
517+ t .Parallel ()
518+ if ! enableSchematicsTests {
519+ t .Skip ("Skipping Schematics Test for VSI Pattern, running terratest instead" )
520+ }
521+
522+ options := setupOptionsSchematics (t , "vsi-sc" , vsiPatternTerraformDir )
523+
524+ options .TerraformVars = []testschematic.TestSchematicTerraformVar {
525+ {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
526+ {Name : "region" , Value : options .Region , DataType : "string" },
527+ {Name : "prefix" , Value : options .Prefix , DataType : "string" },
528+ {Name : "ssh_public_key" , Value : sshPublicKey (t ), DataType : "string" },
529+ {Name : "add_atracker_route" , Value : add_atracker_route , DataType : "bool" },
530+ {Name : "service_endpoints" , Value : "private" , DataType : "string" },
531+ }
532+
533+ err := options .RunSchematicTest ()
534+ assert .NoError (t , err , "Schematic Test had unexpected error" )
535+ }
536+
537+ func TestRunRoksPatternSchematics (t * testing.T ) {
538+ t .Parallel ()
539+ if ! enableSchematicsTests {
540+ t .Skip ("Skipping Schematics Test for ROKS Pattern, running terratest instead" )
541+ }
542+
543+ options := setupOptionsSchematics (t , "ocp-sc" , roksPatternTerraformDir )
544+
545+ options .WaitJobCompleteMinutes = 120
546+
547+ options .TerraformVars = []testschematic.TestSchematicTerraformVar {
548+ {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
549+ {Name : "region" , Value : options .Region , DataType : "string" },
550+ {Name : "prefix" , Value : options .Prefix , DataType : "string" },
551+ {Name : "tags" , Value : options .Tags , DataType : "list(string)" },
552+ {Name : "service_endpoints" , Value : "private" , DataType : "string" },
553+ }
554+
555+ err := options .RunSchematicTest ()
556+ assert .NoError (t , err , "Schematic Test had unexpected error" )
557+ }
558+
559+ func TestRunVPCPatternSchematics (t * testing.T ) {
560+ t .Parallel ()
561+ if ! enableSchematicsTests {
562+ t .Skip ("Skipping Schematics Test for VPC Pattern, running terratest instead" )
563+ }
564+
565+ options := setupOptionsSchematics (t , "vpc-sc" , vpcPatternTerraformDir )
566+
567+ options .TerraformVars = []testschematic.TestSchematicTerraformVar {
568+ {Name : "ibmcloud_api_key" , Value : options .RequiredEnvironmentVars ["TF_VAR_ibmcloud_api_key" ], DataType : "string" , Secure : true },
569+ {Name : "region" , Value : options .Region , DataType : "string" },
570+ {Name : "prefix" , Value : options .Prefix , DataType : "string" },
571+ {Name : "tags" , Value : options .Tags , DataType : "list(string)" },
572+ {Name : "add_atracker_route" , Value : add_atracker_route , DataType : "bool" },
573+ {Name : "service_endpoints" , Value : "private" , DataType : "string" },
574+ }
575+
576+ err := options .RunSchematicTest ()
577+ assert .NoError (t , err , "Schematic Test had unexpected error" )
578+ }
0 commit comments