@@ -963,3 +963,150 @@ func TestMultipleChannels(t *testing.T) {
963963 assert .Equal (t , bsemver .MustParse ("2.0.0" ), * gotVersion )
964964 assert .Equal (t , ptr .To (packageDeprecation (pkgName )), gotDeprecation )
965965}
966+
967+ func TestAllCatalogsDisabled (t * testing.T ) {
968+ pkgName := randPkg ()
969+ listCatalogs := func (ctx context.Context , options ... client.ListOption ) ([]catalogd.ClusterCatalog , error ) {
970+ return []catalogd.ClusterCatalog {
971+ {
972+ Spec : catalogd.ClusterCatalogSpec {
973+ Availability : "Disabled" ,
974+ },
975+ },
976+ {
977+ Spec : catalogd.ClusterCatalogSpec {
978+ Availability : "Disabled" ,
979+ },
980+ },
981+ }, nil
982+ }
983+
984+ getPackage := func (ctx context.Context , cat * catalogd.ClusterCatalog , packageName string ) (* declcfg.DeclarativeConfig , error ) {
985+ return genPackage (pkgName ), nil
986+ }
987+
988+ r := CatalogResolver {
989+ WalkCatalogsFunc : CatalogWalker (listCatalogs , getPackage ),
990+ }
991+
992+ ce := buildFooClusterExtension (pkgName , []string {}, ">=1.0.0" , ocv1alpha1 .UpgradeConstraintPolicyCatalogProvided )
993+ _ , _ , _ , err := r .Resolve (context .Background (), ce , nil )
994+ require .Error (t , err )
995+ assert .Contains (t , err .Error (), "no enabled catalogs found for package" )
996+ }
997+
998+ func TestSomeCatalogsDisabled (t * testing.T ) {
999+ pkgName := randPkg ()
1000+ listCatalogs := func (ctx context.Context , options ... client.ListOption ) ([]catalogd.ClusterCatalog , error ) {
1001+ return []catalogd.ClusterCatalog {
1002+ {
1003+ Spec : catalogd.ClusterCatalogSpec {
1004+ Availability : "Enabled" ,
1005+ },
1006+ },
1007+ {
1008+ Spec : catalogd.ClusterCatalogSpec {
1009+ Availability : "Disabled" ,
1010+ },
1011+ },
1012+ }, nil
1013+ }
1014+
1015+ getPackage := func (ctx context.Context , cat * catalogd.ClusterCatalog , packageName string ) (* declcfg.DeclarativeConfig , error ) {
1016+ return genPackage (pkgName ), nil
1017+ }
1018+
1019+ r := CatalogResolver {
1020+ WalkCatalogsFunc : CatalogWalker (listCatalogs , getPackage ),
1021+ }
1022+
1023+ ce := buildFooClusterExtension (pkgName , []string {}, ">=1.0.0" , ocv1alpha1 .UpgradeConstraintPolicyCatalogProvided )
1024+ gotBundle , gotVersion , _ , err := r .Resolve (context .Background (), ce , nil )
1025+ require .NoError (t , err )
1026+ require .NotNil (t , gotBundle )
1027+ require .Equal (t , bsemver .MustParse ("3.0.0" ), * gotVersion )
1028+ }
1029+
1030+ func TestPriorityRespectedWithDisabledCatalogs (t * testing.T ) {
1031+ pkgName := randPkg ()
1032+ listCatalogs := func (ctx context.Context , options ... client.ListOption ) ([]catalogd.ClusterCatalog , error ) {
1033+ return []catalogd.ClusterCatalog {
1034+ {
1035+ Spec : catalogd.ClusterCatalogSpec {
1036+ Priority : 1 ,
1037+ Availability : "Enabled" ,
1038+ },
1039+ },
1040+ {
1041+ Spec : catalogd.ClusterCatalogSpec {
1042+ Priority : 0 ,
1043+ Availability : "Disabled" ,
1044+ },
1045+ },
1046+ }, nil
1047+ }
1048+
1049+ getPackage := func (ctx context.Context , cat * catalogd.ClusterCatalog , packageName string ) (* declcfg.DeclarativeConfig , error ) {
1050+ return genPackage (pkgName ), nil
1051+ }
1052+
1053+ r := CatalogResolver {
1054+ WalkCatalogsFunc : CatalogWalker (listCatalogs , getPackage ),
1055+ }
1056+
1057+ ce := buildFooClusterExtension (pkgName , []string {}, ">=1.0.0" , ocv1alpha1 .UpgradeConstraintPolicyCatalogProvided )
1058+ gotBundle , gotVersion , _ , err := r .Resolve (context .Background (), ce , nil )
1059+ require .NoError (t , err )
1060+ require .NotNil (t , gotBundle )
1061+ require .Equal (t , bsemver .MustParse ("3.0.0" ), * gotVersion )
1062+ }
1063+
1064+ func TestCatalogWithoutAvailabilityIsEnabled (t * testing.T ) {
1065+ pkgName := randPkg ()
1066+ listCatalogs := func (ctx context.Context , options ... client.ListOption ) ([]catalogd.ClusterCatalog , error ) {
1067+ return []catalogd.ClusterCatalog {
1068+ {
1069+ Spec : catalogd.ClusterCatalogSpec {
1070+ Priority : 1 , // No Availability field set
1071+ },
1072+ },
1073+ {
1074+ Spec : catalogd.ClusterCatalogSpec {
1075+ Availability : "Disabled" , // This should be skipped
1076+ Priority : 2 ,
1077+ },
1078+ },
1079+ }, nil
1080+ }
1081+
1082+ getPackage := func (ctx context.Context , cat * catalogd.ClusterCatalog , packageName string ) (* declcfg.DeclarativeConfig , error ) {
1083+ if cat .Spec .Availability == "" || cat .Spec .Availability == "Enabled" {
1084+ return genPackage (pkgName ), nil
1085+ }
1086+ return & declcfg.DeclarativeConfig {
1087+ Packages : []declcfg.Package {{Name : pkgName }},
1088+ Channels : []declcfg.Channel {
1089+ {
1090+ Package : pkgName ,
1091+ Name : "alpha" ,
1092+ Entries : []declcfg.ChannelEntry {
1093+ {Name : bundleName (pkgName , "3.0.0" )},
1094+ },
1095+ },
1096+ },
1097+ Bundles : []declcfg.Bundle {
1098+ genBundle (pkgName , "3.0.0" ),
1099+ },
1100+ }, nil
1101+ }
1102+
1103+ r := CatalogResolver {
1104+ WalkCatalogsFunc : CatalogWalker (listCatalogs , getPackage ),
1105+ }
1106+
1107+ ce := buildFooClusterExtension (pkgName , []string {}, ">=1.0.0" , ocv1alpha1 .UpgradeConstraintPolicyCatalogProvided )
1108+ gotBundle , gotVersion , _ , err := r .Resolve (context .Background (), ce , nil )
1109+ require .NoError (t , err )
1110+ require .NotNil (t , gotBundle )
1111+ require .Equal (t , bsemver .MustParse ("3.0.0" ), * gotVersion , "expected version to be 3.0.0, but got %s" , gotVersion )
1112+ }
0 commit comments