@@ -24,7 +24,27 @@ func TestInstalledPackageVariableSource(t *testing.T) {
24
24
Name : "stable" ,
25
25
Entries : []declcfg.ChannelEntry {
26
26
{
27
- Name : "test-package.v1.0.0" ,
27
+ Name : "test-package.v0.0.1" ,
28
+ },
29
+ {
30
+ Name : "test-package.v0.0.2" ,
31
+ Replaces : "test-package.v0.0.1" ,
32
+ },
33
+ {
34
+ Name : "test-package.v0.1.0" ,
35
+ Replaces : "test-package.v0.0.2" ,
36
+ },
37
+ {
38
+ Name : "test-package.v0.1.1" ,
39
+ Replaces : "test-package.v0.1.0" ,
40
+ },
41
+ {
42
+ Name : "test-package.v0.2.0" ,
43
+ Replaces : "test-package.v0.1.1" ,
44
+ },
45
+ {
46
+ Name : "test-package.v1.0.0" ,
47
+ Replaces : "test-package.v0.2.0" ,
28
48
},
29
49
{
30
50
Name : "test-package.v2.0.0" ,
@@ -53,6 +73,51 @@ func TestInstalledPackageVariableSource(t *testing.T) {
53
73
},
54
74
}}
55
75
bundleList := []* catalogmetadata.Bundle {
76
+ {Bundle : declcfg.Bundle {
77
+ Name : "test-package.v0.0.1" ,
78
+ Package : "test-package" ,
79
+ Image :
"registry.io/repo/[email protected] " ,
80
+ Properties : []property.Property {
81
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.0.1"}` )},
82
+ }},
83
+ InChannels : []* catalogmetadata.Channel {& channel },
84
+ },
85
+ {Bundle : declcfg.Bundle {
86
+ Name : "test-package.v0.0.2" ,
87
+ Package : "test-package" ,
88
+ Image :
"registry.io/repo/[email protected] " ,
89
+ Properties : []property.Property {
90
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.0.2"}` )},
91
+ }},
92
+ InChannels : []* catalogmetadata.Channel {& channel },
93
+ },
94
+ {Bundle : declcfg.Bundle {
95
+ Name : "test-package.v0.1.0" ,
96
+ Package : "test-package" ,
97
+ Image :
"registry.io/repo/[email protected] " ,
98
+ Properties : []property.Property {
99
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.1.0"}` )},
100
+ }},
101
+ InChannels : []* catalogmetadata.Channel {& channel },
102
+ },
103
+ {Bundle : declcfg.Bundle {
104
+ Name : "test-package.v0.1.1" ,
105
+ Package : "test-package" ,
106
+ Image :
"registry.io/repo/[email protected] " ,
107
+ Properties : []property.Property {
108
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.1.1"}` )},
109
+ }},
110
+ InChannels : []* catalogmetadata.Channel {& channel },
111
+ },
112
+ {Bundle : declcfg.Bundle {
113
+ Name : "test-package.v0.2.0" ,
114
+ Package : "test-package" ,
115
+ Image :
"registry.io/repo/[email protected] " ,
116
+ Properties : []property.Property {
117
+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "test-package", "version": "0.2.0"}` )},
118
+ }},
119
+ InChannels : []* catalogmetadata.Channel {& channel },
120
+ },
56
121
{Bundle : declcfg.Bundle {
57
122
Name : "test-package.v1.0.0" ,
58
123
Package : "test-package" ,
@@ -118,33 +183,75 @@ func TestInstalledPackageVariableSource(t *testing.T) {
118
183
},
119
184
}
120
185
121
- const bundleImage = "registry.io/repo/[email protected] "
122
186
fakeCatalogClient := testutil .NewFakeCatalogClient (bundleList )
123
187
124
188
t .Run ("with ForceSemverUpgradeConstraints feature gate enabled" , func (t * testing.T ) {
125
189
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
126
190
127
- ipvs , err := variablesources .NewInstalledPackageVariableSource (& fakeCatalogClient , bundleImage )
128
- require .NoError (t , err )
191
+ t .Run ("with non-zero major version" , func (t * testing.T ) {
192
+ const bundleImage = "registry.io/repo/[email protected] "
193
+ ipvs , err := variablesources .NewInstalledPackageVariableSource (& fakeCatalogClient , bundleImage )
194
+ require .NoError (t , err )
129
195
130
- variables , err := ipvs .GetVariables (context .TODO ())
131
- require .NoError (t , err )
132
- require .Len (t , variables , 1 )
133
- packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
134
- assert .True (t , ok )
135
- assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
196
+ variables , err := ipvs .GetVariables (context .TODO ())
197
+ require .NoError (t , err )
198
+ require .Len (t , variables , 1 )
199
+ packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
200
+ assert .True (t , ok )
201
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
136
202
137
- // ensure bundles are in version order (high to low)
138
- bundles := packageVariable .Bundles ()
139
- require .Len (t , bundles , 3 )
140
- assert .Equal (t , "test-package.v2.2.0" , packageVariable .Bundles ()[0 ].Name )
141
- assert .Equal (t , "test-package.v2.1.0" , packageVariable .Bundles ()[1 ].Name )
142
- assert .Equal (t , "test-package.v2.0.0" , packageVariable .Bundles ()[2 ].Name )
203
+ // ensure bundles are in version order (high to low)
204
+ bundles := packageVariable .Bundles ()
205
+ require .Len (t , bundles , 3 )
206
+ assert .Equal (t , "test-package.v2.2.0" , packageVariable .Bundles ()[0 ].Name )
207
+ assert .Equal (t , "test-package.v2.1.0" , packageVariable .Bundles ()[1 ].Name )
208
+ assert .Equal (t , "test-package.v2.0.0" , packageVariable .Bundles ()[2 ].Name )
209
+ })
210
+
211
+ t .Run ("with zero major version" , func (t * testing.T ) {
212
+ t .Run ("with zero minor version" , func (t * testing.T ) {
213
+ const bundleImage = "registry.io/repo/[email protected] "
214
+ ipvs , err := variablesources .NewInstalledPackageVariableSource (& fakeCatalogClient , bundleImage )
215
+ require .NoError (t , err )
216
+
217
+ variables , err := ipvs .GetVariables (context .TODO ())
218
+ require .NoError (t , err )
219
+ require .Len (t , variables , 1 )
220
+ packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
221
+ assert .True (t , ok )
222
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
223
+
224
+ // No upgrades are allowed in major version zero when minor version is also zero
225
+ bundles := packageVariable .Bundles ()
226
+ require .Len (t , bundles , 1 )
227
+ assert .Equal (t , "test-package.v0.0.1" , packageVariable .Bundles ()[0 ].Name )
228
+ })
229
+
230
+ t .Run ("with non-zero minor version" , func (t * testing.T ) {
231
+ const bundleImage = "registry.io/repo/[email protected] "
232
+ ipvs , err := variablesources .NewInstalledPackageVariableSource (& fakeCatalogClient , bundleImage )
233
+ require .NoError (t , err )
234
+
235
+ variables , err := ipvs .GetVariables (context .TODO ())
236
+ require .NoError (t , err )
237
+ require .Len (t , variables , 1 )
238
+ packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
239
+ assert .True (t , ok )
240
+ assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
241
+
242
+ // Patch version upgrades are allowed, but not minor upgrades
243
+ bundles := packageVariable .Bundles ()
244
+ require .Len (t , bundles , 2 )
245
+ assert .Equal (t , "test-package.v0.1.1" , packageVariable .Bundles ()[0 ].Name )
246
+ assert .Equal (t , "test-package.v0.1.0" , packageVariable .Bundles ()[1 ].Name )
247
+ })
248
+ })
143
249
})
144
250
145
251
t .Run ("with ForceSemverUpgradeConstraints feature gate disabled" , func (t * testing.T ) {
146
252
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , false )()
147
253
254
+ const bundleImage = "registry.io/repo/[email protected] "
148
255
ipvs , err := variablesources .NewInstalledPackageVariableSource (& fakeCatalogClient , bundleImage )
149
256
require .NoError (t , err )
150
257
0 commit comments