@@ -379,81 +379,102 @@ func TestRegistryV1SuiteGenerateOwnNamespace(t *testing.T) {
379379 require .Equal (t , strings .Join (watchNamespaces , "," ), dep .(* appsv1.Deployment ).Spec .Template .Annotations [olmNamespaces ])
380380}
381381
382- func TestRegistryV1SuiteGenerateErrorMultiNamespaceEmpty (t * testing.T ) {
383- t .Log ("RegistryV1 Suite Convert" )
384- t .Log ("It should generate objects successfully based on target namespaces" )
385-
386- t .Log ("It should error when multinamespace mode is supported with an empty string in target namespaces" )
387- baseCSV , svc := getBaseCsvAndService ()
388- csv := baseCSV .DeepCopy ()
389- csv .Spec .InstallModes = []v1alpha1.InstallMode {{Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true }}
390-
391- t .Log ("By creating a registry v1 bundle" )
392- watchNamespaces := []string {"testWatchNs1" , "" }
393- unstructuredSvc := convertToUnstructured (t , svc )
394- registryv1Bundle := convert.RegistryV1 {
395- PackageName : "testPkg" ,
396- CSV : * csv ,
397- Others : []unstructured.Unstructured {unstructuredSvc },
398- }
399-
400- t .Log ("By converting to plain" )
401- plainBundle , err := convert .Convert (registryv1Bundle , installNamespace , watchNamespaces )
402- require .Error (t , err )
403- require .Nil (t , plainBundle )
404- }
405-
406- func TestRegistryV1SuiteGenerateErrorSingleNamespaceDisabled (t * testing.T ) {
407- t .Log ("RegistryV1 Suite Convert" )
408- t .Log ("It should generate objects successfully based on target namespaces" )
409-
410- t .Log ("It should error when single namespace mode is disabled with more than one target namespaces" )
411- baseCSV , svc := getBaseCsvAndService ()
412- csv := baseCSV .DeepCopy ()
413- csv .Spec .InstallModes = []v1alpha1.InstallMode {{Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : false }}
414-
415- t .Log ("By creating a registry v1 bundle" )
416- watchNamespaces := []string {"testWatchNs1" , "testWatchNs2" }
417- unstructuredSvc := convertToUnstructured (t , svc )
418- registryv1Bundle := convert.RegistryV1 {
419- PackageName : "testPkg" ,
420- CSV : * csv ,
421- Others : []unstructured.Unstructured {unstructuredSvc },
422- }
423-
424- t .Log ("By converting to plain" )
425- plainBundle , err := convert .Convert (registryv1Bundle , installNamespace , watchNamespaces )
426- require .Error (t , err )
427- require .Nil (t , plainBundle )
428- }
429-
430- func TestRegistryV1SuiteGenerateErrorAllNamespaceDisabled (t * testing.T ) {
431- t .Log ("RegistryV1 Suite Convert" )
432- t .Log ("It should generate objects successfully based on target namespaces" )
433-
434- t .Log ("It should error when all namespace mode is disabled with target namespace containing an empty string" )
435- baseCSV , svc := getBaseCsvAndService ()
436- csv := baseCSV .DeepCopy ()
437- csv .Spec .InstallModes = []v1alpha1.InstallMode {
438- {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : false },
439- {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : true },
440- {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : true },
441- {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
442- }
382+ func TestConvertInstallModeValidation (t * testing.T ) {
383+ for _ , tc := range []struct {
384+ description string
385+ installModes []v1alpha1.InstallMode
386+ installNamespace string
387+ watchNamespaces []string
388+ }{
389+ {
390+ description : "fails on AllNamespaces install mode when CSV does not support it" ,
391+ installNamespace : "install-namespace" ,
392+ watchNamespaces : []string {corev1 .NamespaceAll },
393+ installModes : []v1alpha1.InstallMode {
394+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : false },
395+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : true },
396+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : true },
397+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
398+ },
399+ }, {
400+ description : "fails on SingleNamespace install mode when CSV does not support it" ,
401+ installNamespace : "install-namespace" ,
402+ watchNamespaces : []string {"watch-namespace" },
403+ installModes : []v1alpha1.InstallMode {
404+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : true },
405+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : true },
406+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : false },
407+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
408+ },
409+ }, {
410+ description : "fails on OwnNamespace install mode when CSV does not support it and watch namespace is not install namespace" ,
411+ installNamespace : "install-namespace" ,
412+ watchNamespaces : []string {"watch-namespace" },
413+ installModes : []v1alpha1.InstallMode {
414+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : true },
415+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : true },
416+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : false },
417+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
418+ },
419+ }, {
420+ description : "fails on MultiNamespace install mode when CSV does not support it" ,
421+ installNamespace : "install-namespace" ,
422+ watchNamespaces : []string {"watch-namespace-one" , "watch-namespace-two" , "watch-namespace-three" },
423+ installModes : []v1alpha1.InstallMode {
424+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : true },
425+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : true },
426+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : true },
427+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : false },
428+ },
429+ }, {
430+ description : "fails on MultiNamespace install mode when CSV supports it but watchNamespaces is empty" ,
431+ installNamespace : "install-namespace" ,
432+ watchNamespaces : []string {},
433+ installModes : []v1alpha1.InstallMode {
434+ // because install mode is inferred by the watchNamespaces parameter
435+ // force MultiNamespace install by disabling other modes
436+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : false },
437+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : false },
438+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : false },
439+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
440+ },
441+ }, {
442+ description : "fails on MultiNamespace install mode when CSV supports it but watchNamespaces is nil" ,
443+ installNamespace : "install-namespace" ,
444+ watchNamespaces : nil ,
445+ installModes : []v1alpha1.InstallMode {
446+ // because install mode is inferred by the watchNamespaces parameter
447+ // force MultiNamespace install by disabling other modes
448+ {Type : v1alpha1 .InstallModeTypeAllNamespaces , Supported : false },
449+ {Type : v1alpha1 .InstallModeTypeOwnNamespace , Supported : false },
450+ {Type : v1alpha1 .InstallModeTypeSingleNamespace , Supported : false },
451+ {Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true },
452+ },
453+ },
454+ } {
455+ t .Run (tc .description , func (t * testing.T ) {
456+ t .Log ("RegistryV1 Suite Convert" )
457+ t .Log ("It should generate objects successfully based on target namespaces" )
458+
459+ t .Log ("It should error when all namespace mode is disabled with target namespace containing an empty string" )
460+ baseCSV , svc := getBaseCsvAndService ()
461+ csv := baseCSV .DeepCopy ()
462+ csv .Spec .InstallModes = tc .installModes
463+
464+ t .Log ("By creating a registry v1 bundle" )
465+ unstructuredSvc := convertToUnstructured (t , svc )
466+ registryv1Bundle := convert.RegistryV1 {
467+ PackageName : "testPkg" ,
468+ CSV : * csv ,
469+ Others : []unstructured.Unstructured {unstructuredSvc },
470+ }
443471
444- t .Log ("By creating a registry v1 bundle" )
445- watchNamespaces := []string {"" }
446- unstructuredSvc := convertToUnstructured (t , svc )
447- registryv1Bundle := convert.RegistryV1 {
448- PackageName : "testPkg" ,
449- CSV : * csv ,
450- Others : []unstructured.Unstructured {unstructuredSvc },
472+ t .Log ("By converting to plain" )
473+ plainBundle , err := convert .Convert (registryv1Bundle , tc .installNamespace , tc .watchNamespaces )
474+ require .Error (t , err )
475+ require .Nil (t , plainBundle )
476+ })
451477 }
452-
453- t .Log ("By converting to plain" )
454- plainBundle , err := convert .Convert (registryv1Bundle , installNamespace , watchNamespaces )
455- require .Error (t , err )
456- require .Nil (t , plainBundle )
457478}
458479
459480func TestRegistryV1SuiteReadBundleFileSystem (t * testing.T ) {
0 commit comments