@@ -140,7 +140,27 @@ func TestInstalledPackageVariables(t *testing.T) {
140
140
Name : "stable" ,
141
141
Entries : []declcfg.ChannelEntry {
142
142
{
143
- Name : "test-package.v1.0.0" ,
143
+ Name : "test-package.v0.0.1" ,
144
+ },
145
+ {
146
+ Name : "test-package.v0.0.2" ,
147
+ Replaces : "test-package.v0.0.1" ,
148
+ },
149
+ {
150
+ Name : "test-package.v0.1.0" ,
151
+ Replaces : "test-package.v0.0.2" ,
152
+ },
153
+ {
154
+ Name : "test-package.v0.1.1" ,
155
+ Replaces : "test-package.v0.1.0" ,
156
+ },
157
+ {
158
+ Name : "test-package.v0.2.0" ,
159
+ Replaces : "test-package.v0.1.1" ,
160
+ },
161
+ {
162
+ Name : "test-package.v1.0.0" ,
163
+ Replaces : "test-package.v0.2.0" ,
144
164
},
145
165
{
146
166
Name : "test-package.v2.0.0" ,
@@ -169,6 +189,51 @@ func TestInstalledPackageVariables(t *testing.T) {
169
189
},
170
190
}}
171
191
allBundles := []* catalogmetadata.Bundle {
192
+ {Bundle : declcfg.Bundle {
193
+ Name : "test-package.v0.0.1" ,
194
+ Package : "test-package" ,
195
+ Image :
"registry.io/repo/[email protected] " ,
196
+ Properties : []property.Property {
197
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.0.1"}` )},
198
+ }},
199
+ InChannels : []* catalogmetadata.Channel {& channel },
200
+ },
201
+ {Bundle : declcfg.Bundle {
202
+ Name : "test-package.v0.0.2" ,
203
+ Package : "test-package" ,
204
+ Image :
"registry.io/repo/[email protected] " ,
205
+ Properties : []property.Property {
206
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.0.2"}` )},
207
+ }},
208
+ InChannels : []* catalogmetadata.Channel {& channel },
209
+ },
210
+ {Bundle : declcfg.Bundle {
211
+ Name : "test-package.v0.1.0" ,
212
+ Package : "test-package" ,
213
+ Image :
"registry.io/repo/[email protected] " ,
214
+ Properties : []property.Property {
215
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.1.0"}` )},
216
+ }},
217
+ InChannels : []* catalogmetadata.Channel {& channel },
218
+ },
219
+ {Bundle : declcfg.Bundle {
220
+ Name : "test-package.v0.1.1" ,
221
+ Package : "test-package" ,
222
+ Image :
"registry.io/repo/[email protected] " ,
223
+ Properties : []property.Property {
224
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.1.1"}` )},
225
+ }},
226
+ InChannels : []* catalogmetadata.Channel {& channel },
227
+ },
228
+ {Bundle : declcfg.Bundle {
229
+ Name : "test-package.v0.2.0" ,
230
+ Package : "test-package" ,
231
+ Image :
"registry.io/repo/[email protected] " ,
232
+ Properties : []property.Property {
233
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.2.0"}` )},
234
+ }},
235
+ InChannels : []* catalogmetadata.Channel {& channel },
236
+ },
172
237
{Bundle : declcfg.Bundle {
173
238
Name : "test-package.v1.0.0" ,
174
239
Package : "test-package" ,
@@ -259,6 +324,60 @@ func TestInstalledPackageVariables(t *testing.T) {
259
324
return bundleDeployments
260
325
}
261
326
327
+ t .Run ("with ForceSemverUpgradeConstraints feature gate enabled" , func (t * testing.T ) {
328
+ defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
329
+
330
+ t .Run ("with non-zero major version" , func (t * testing.T ) {
331
+ const bundleImage = "registry.io/repo/[email protected] "
332
+ installedPackages , err := variablesources .InstalledPackageVariables (allBundles , fakeBundleDeployments (bundleImage ))
333
+ require .NoError (t , err )
334
+
335
+ require .Len (t , installedPackages , 1 )
336
+ packageVariable := installedPackages [0 ]
337
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
338
+
339
+ // ensure bundles are in version order (high to low)
340
+ bundles := packageVariable .Bundles ()
341
+ require .Len (t , bundles , 3 )
342
+ assert .Equal (t , "test-package.v2.2.0" , packageVariable .Bundles ()[0 ].Name )
343
+ assert .Equal (t , "test-package.v2.1.0" , packageVariable .Bundles ()[1 ].Name )
344
+ assert .Equal (t , "test-package.v2.0.0" , packageVariable .Bundles ()[2 ].Name )
345
+ })
346
+
347
+ t .Run ("with zero major version" , func (t * testing.T ) {
348
+ t .Run ("with zero minor version" , func (t * testing.T ) {
349
+ const bundleImage = "registry.io/repo/[email protected] "
350
+ installedPackages , err := variablesources .InstalledPackageVariables (allBundles , fakeBundleDeployments (bundleImage ))
351
+ require .NoError (t , err )
352
+
353
+ require .Len (t , installedPackages , 1 )
354
+ packageVariable := installedPackages [0 ]
355
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
356
+
357
+ // No upgrades are allowed in major version zero when minor version is also zero
358
+ bundles := packageVariable .Bundles ()
359
+ require .Len (t , bundles , 1 )
360
+ assert .Equal (t , "test-package.v0.0.1" , packageVariable .Bundles ()[0 ].Name )
361
+ })
362
+
363
+ t .Run ("with non-zero minor version" , func (t * testing.T ) {
364
+ const bundleImage = "registry.io/repo/[email protected] "
365
+ installedPackages , err := variablesources .InstalledPackageVariables (allBundles , fakeBundleDeployments (bundleImage ))
366
+ require .NoError (t , err )
367
+
368
+ require .Len (t , installedPackages , 1 )
369
+ packageVariable := installedPackages [0 ]
370
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
371
+
372
+ // Patch version upgrades are allowed, but not minor upgrades
373
+ bundles := packageVariable .Bundles ()
374
+ require .Len (t , bundles , 2 )
375
+ assert .Equal (t , "test-package.v0.1.1" , packageVariable .Bundles ()[0 ].Name )
376
+ assert .Equal (t , "test-package.v0.1.0" , packageVariable .Bundles ()[1 ].Name )
377
+ })
378
+ })
379
+ })
380
+
262
381
t .Run ("with ForceSemverUpgradeConstraints feature gate disabled" , func (t * testing.T ) {
263
382
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , false )()
264
383
0 commit comments