@@ -1066,7 +1066,19 @@ func TestBoundaryCases(t *testing.T) {
10661066 {
10671067 name : "Error/empty DeclarativeConfig" ,
10681068 testFunc : func (t * testing.T ) {
1069- cfg := & declcfg.DeclarativeConfig {}
1069+ cfg := & declcfg.DeclarativeConfig {
1070+ Bundles : []declcfg.Bundle {
1071+ {
1072+ Schema : "olm.bundle" ,
1073+ Name : "test.v0.9.0" ,
1074+ Package : "test" ,
1075+ Image : "quay.io/test/test-bundle:v0.9.0" ,
1076+ Properties : []property.Property {
1077+ property .MustBuildPackage ("test" , "0.9.0" ),
1078+ },
1079+ },
1080+ },
1081+ }
10701082 substitution := Substitute {Name : "quay.io/test/test-bundle:v1.0.0-alpha" , Base : "test.v0.9.0" }
10711083 template := createMockTemplate ()
10721084 ctx := context .Background ()
@@ -1080,6 +1092,17 @@ func TestBoundaryCases(t *testing.T) {
10801092 testFunc : func (t * testing.T ) {
10811093 cfg := & declcfg.DeclarativeConfig {
10821094 Channels : []declcfg.Channel {},
1095+ Bundles : []declcfg.Bundle {
1096+ {
1097+ Schema : "olm.bundle" ,
1098+ Name : "test.v0.9.0" ,
1099+ Package : "test" ,
1100+ Image : "quay.io/test/test-bundle:v0.9.0" ,
1101+ Properties : []property.Property {
1102+ property .MustBuildPackage ("test" , "0.9.0" ),
1103+ },
1104+ },
1105+ },
10831106 }
10841107 substitution := Substitute {Name : "quay.io/test/test-bundle:v1.0.0-alpha" , Base : "test.v0.9.0" }
10851108 template := createMockTemplate ()
@@ -1108,6 +1131,17 @@ func TestBoundaryCases(t *testing.T) {
11081131 Entries : []declcfg.ChannelEntry {},
11091132 },
11101133 },
1134+ Bundles : []declcfg.Bundle {
1135+ {
1136+ Schema : "olm.bundle" ,
1137+ Name : "test.v0.9.0" ,
1138+ Package : "test" ,
1139+ Image : "quay.io/test/test-bundle:v0.9.0" ,
1140+ Properties : []property.Property {
1141+ property .MustBuildPackage ("test" , "0.9.0" ),
1142+ },
1143+ },
1144+ },
11111145 }
11121146 substitution := Substitute {Name : "quay.io/test/test-bundle:v1.0.0-alpha" , Base : "test.v0.9.0" }
11131147 template := createMockTemplate ()
@@ -1213,24 +1247,38 @@ func TestBoundaryCases(t *testing.T) {
12131247 {
12141248 name : "Error/substitution with invalid declarative config - missing package" ,
12151249 testFunc : func (t * testing.T ) {
1216- // Create a config with a bundle that references a non-existent package
1250+ // Create a config with a bundle in the catalog that is not referenced in any channels
12171251 cfg := & declcfg.DeclarativeConfig {
12181252 Packages : []declcfg.Package {
12191253 {
12201254 Schema : "olm.package" ,
1221- Name : "nonexistent " ,
1255+ Name : "testoperator " ,
12221256 DefaultChannel : "stable" ,
12231257 },
12241258 },
1259+ Channels : []declcfg.Channel {
1260+ {
1261+ Schema : "olm.channel" ,
1262+ Name : "stable" ,
1263+ Package : "testoperator" ,
1264+ Entries : []declcfg.ChannelEntry {
1265+ {Name : "testoperator.v1.0.0" },
1266+ },
1267+ },
1268+ },
12251269 Bundles : []declcfg.Bundle {
12261270 {
1227- Name : "testoperator.v1.1 .0" , // This is the substitution name we're testing
1228- Package : "nonexistent" , // This package exists but bundle name doesn't match
1271+ Name : "testoperator.v1.0 .0" , // Base bundle for substitution
1272+ Package : "testoperator" ,
12291273 Properties : []property.Property {
1230- {
1231- Type : property .TypePackage ,
1232- Value : json .RawMessage (`{"packageName":"nonexistent","version":"1.1.0"}` ),
1233- },
1274+ property .MustBuildPackage ("testoperator" , "1.0.0" ),
1275+ },
1276+ },
1277+ {
1278+ Name : "testoperator.v1.1.0" , // Extra bundle not in any channel
1279+ Package : "testoperator" ,
1280+ Properties : []property.Property {
1281+ property .MustBuildPackage ("testoperator" , "1.1.0" ),
12341282 },
12351283 },
12361284 },
@@ -1246,7 +1294,7 @@ func TestBoundaryCases(t *testing.T) {
12461294 {
12471295 name : "Error/substitution with invalid declarative config - bundle missing olm.package property" ,
12481296 testFunc : func (t * testing.T ) {
1249- // Create a config with a bundle that has no olm.package property
1297+ // Create a config where the base bundle has no olm.package property
12501298 cfg := & declcfg.DeclarativeConfig {
12511299 Packages : []declcfg.Package {
12521300 {
@@ -1257,7 +1305,7 @@ func TestBoundaryCases(t *testing.T) {
12571305 },
12581306 Bundles : []declcfg.Bundle {
12591307 {
1260- Name : "testoperator.v1.1 .0" , // This is the substitution name we're testing
1308+ Name : "testoperator.v1.0 .0" , // Base bundle for substitution, missing olm.package property
12611309 Package : "testoperator" ,
12621310 Properties : []property.Property {}, // No olm.package property
12631311 },
@@ -1271,6 +1319,65 @@ func TestBoundaryCases(t *testing.T) {
12711319 require .Contains (t , err .Error (), "must have exactly 1 \" olm.package\" property" )
12721320 },
12731321 },
1322+ {
1323+ name : "Error/base bundle does not exist in catalog" ,
1324+ testFunc : func (t * testing.T ) {
1325+ cfg := & declcfg.DeclarativeConfig {
1326+ Packages : []declcfg.Package {
1327+ {
1328+ Schema : "olm.package" ,
1329+ Name : "testoperator" ,
1330+ DefaultChannel : "stable" ,
1331+ },
1332+ },
1333+ Bundles : []declcfg.Bundle {
1334+ {
1335+ Name : "testoperator.v1.1.0" ,
1336+ Package : "testoperator" ,
1337+ Properties : []property.Property {
1338+ property .MustBuildPackage ("testoperator" , "1.1.0" ),
1339+ },
1340+ },
1341+ },
1342+ }
1343+ substitution := Substitute {Name : "quay.io/test/testoperator-bundle:v1.2.0-alpha" , Base : "testoperator.v1.0.0" }
1344+ template := createMockTemplate ()
1345+ ctx := context .Background ()
1346+ err := template .processSubstitution (ctx , cfg , substitution )
1347+ require .Error (t , err )
1348+ require .Contains (t , err .Error (), "does not exist in catalog" )
1349+ },
1350+ },
1351+ {
1352+ name : "Error/substitute bundle version not greater than base bundle" ,
1353+ testFunc : func (t * testing.T ) {
1354+ cfg := & declcfg.DeclarativeConfig {
1355+ Packages : []declcfg.Package {
1356+ {
1357+ Schema : "olm.package" ,
1358+ Name : "testoperator" ,
1359+ DefaultChannel : "stable" ,
1360+ },
1361+ },
1362+ Bundles : []declcfg.Bundle {
1363+ {
1364+ Name : "testoperator-v1.2.0-beta" ,
1365+ Package : "testoperator" ,
1366+ Properties : []property.Property {
1367+ property .MustBuildPackageRelease ("testoperator" , "1.2.0" , "beta" ),
1368+ },
1369+ },
1370+ },
1371+ }
1372+ // Trying to substitute with an alpha release (lower than beta)
1373+ substitution := Substitute {Name : "quay.io/test/testoperator-bundle:v1.2.0-alpha" , Base : "testoperator-v1.2.0-beta" }
1374+ template := createMockTemplate ()
1375+ ctx := context .Background ()
1376+ err := template .processSubstitution (ctx , cfg , substitution )
1377+ require .Error (t , err )
1378+ require .Contains (t , err .Error (), "is not less than" )
1379+ },
1380+ },
12741381 }
12751382
12761383 for _ , tt := range tests {
0 commit comments