@@ -130,6 +130,9 @@ var (
130130 "disaster-recover-site" : true ,
131131 "power-vpn-connections" : false ,
132132 }
133+ defaultSysType = "s922"
134+ newSysType = "s1022"
135+ invalidRegion = "foo"
133136)
134137
135138func validInstallConfig () * types.InstallConfig {
@@ -556,6 +559,89 @@ func TestValidatePERAvailability(t *testing.T) {
556559 }
557560}
558561
562+ func TestValidateSystemTypeForRegion (t * testing.T ) {
563+ cases := []struct {
564+ name string
565+ edits editFunctions
566+ errorMsg string
567+ }{
568+ {
569+ name : "Unknown Region specified" ,
570+ edits : editFunctions {
571+ func (ic * types.InstallConfig ) {
572+ ic .Platform .PowerVS .Region = invalidRegion
573+ ic .ControlPlane .Platform .PowerVS = validMachinePool ()
574+ ic .ControlPlane .Platform .PowerVS .SysType = defaultSysType
575+ },
576+ },
577+ errorMsg : fmt .Sprintf ("failed to obtain available SysTypes for: %s" , invalidRegion ),
578+ },
579+ {
580+ name : "No Platform block" ,
581+ edits : editFunctions {
582+ func (ic * types.InstallConfig ) {
583+ ic .ControlPlane .Platform .PowerVS = nil
584+ },
585+ },
586+ errorMsg : "" ,
587+ },
588+ {
589+ name : "Structure present, but no SysType specified" ,
590+ edits : editFunctions {
591+ func (ic * types.InstallConfig ) {
592+ ic .ControlPlane .Platform .PowerVS = validMachinePool ()
593+ },
594+ },
595+ errorMsg : "" ,
596+ },
597+ {
598+ name : "Unavailable SysType specified for Dallas Region" ,
599+ edits : editFunctions {
600+ func (ic * types.InstallConfig ) {
601+ ic .Platform .PowerVS .Region = validRegion
602+ ic .ControlPlane .Platform .PowerVS = validMachinePool ()
603+ ic .ControlPlane .Platform .PowerVS .SysType = newSysType
604+ },
605+ },
606+ errorMsg : fmt .Sprintf ("%s is not available in: %s" , newSysType , validRegion ),
607+ },
608+ {
609+ name : "Good Region/SysType combo specified" ,
610+ edits : editFunctions {
611+ func (ic * types.InstallConfig ) {
612+ ic .Platform .PowerVS .Region = validRegion
613+ ic .ControlPlane .Platform .PowerVS = validMachinePool ()
614+ ic .ControlPlane .Platform .PowerVS .SysType = defaultSysType
615+ },
616+ },
617+ errorMsg : "" ,
618+ },
619+ }
620+ setMockEnvVars ()
621+
622+ mockCtrl := gomock .NewController (t )
623+ defer mockCtrl .Finish ()
624+
625+ powervsClient := mock .NewMockAPI (mockCtrl )
626+
627+ // Run tests
628+ for _ , tc := range cases {
629+ t .Run (tc .name , func (t * testing.T ) {
630+ editedInstallConfig := validInstallConfig ()
631+ for _ , edit := range tc .edits {
632+ edit (editedInstallConfig )
633+ }
634+
635+ aggregatedErrors := powervs .ValidateSystemTypeForRegion (powervsClient , editedInstallConfig )
636+ if tc .errorMsg != "" {
637+ assert .Regexp (t , tc .errorMsg , aggregatedErrors )
638+ } else {
639+ assert .NoError (t , aggregatedErrors )
640+ }
641+ })
642+ }
643+ }
644+
559645func setMockEnvVars () {
560646 os .Setenv ("POWERVS_AUTH_FILEPATH" , "./tmp/powervs/config.json" )
561647 os .Setenv ("IBMID" , "foo" )
0 commit comments