1
1
package variablesources_test
2
2
3
3
import (
4
- "context"
5
4
"encoding/json"
6
5
"testing"
7
6
8
7
"github.com/operator-framework/deppy/pkg/deppy"
9
8
"github.com/operator-framework/operator-registry/alpha/declcfg"
10
9
"github.com/operator-framework/operator-registry/alpha/property"
10
+ rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
11
11
"github.com/stretchr/testify/assert"
12
12
"github.com/stretchr/testify/require"
13
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
14
featuregatetesting "k8s.io/component-base/featuregate/testing"
14
15
15
16
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
16
- olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
17
17
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
18
18
"github.com/operator-framework/operator-controller/pkg/features"
19
19
)
20
20
21
- func TestInstalledPackageVariableSource (t * testing.T ) {
21
+ func TestMakeInstalledPackageVariables (t * testing.T ) {
22
22
someOtherPackageChannel := catalogmetadata.Channel {Channel : declcfg.Channel {
23
23
Name : "stable" ,
24
24
Package : "some-other-package" ,
@@ -81,7 +81,7 @@ func TestInstalledPackageVariableSource(t *testing.T) {
81
81
},
82
82
},
83
83
}}
84
- bundleList := []* catalogmetadata.Bundle {
84
+ allBundles := []* catalogmetadata.Bundle {
85
85
{Bundle : declcfg.Bundle {
86
86
Name : "test-package.v0.0.1" ,
87
87
Package : "test-package" ,
@@ -201,19 +201,40 @@ func TestInstalledPackageVariableSource(t *testing.T) {
201
201
},
202
202
}
203
203
204
+ fakeBundleDeployment := func (name , bundleImage string ) rukpakv1alpha1.BundleDeployment {
205
+ return rukpakv1alpha1.BundleDeployment {
206
+ ObjectMeta : metav1.ObjectMeta {
207
+ Name : name ,
208
+ },
209
+ Spec : rukpakv1alpha1.BundleDeploymentSpec {
210
+ Template : & rukpakv1alpha1.BundleTemplate {
211
+ Spec : rukpakv1alpha1.BundleSpec {
212
+ Source : rukpakv1alpha1.BundleSource {
213
+ Image : & rukpakv1alpha1.ImageSource {
214
+ Ref : bundleImage ,
215
+ },
216
+ },
217
+ },
218
+ },
219
+ },
220
+ }
221
+ }
222
+
204
223
t .Run ("with ForceSemverUpgradeConstraints feature gate enabled" , func (t * testing.T ) {
205
224
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , true )()
206
225
207
226
t .Run ("with non-zero major version" , func (t * testing.T ) {
208
227
const bundleImage = "registry.io/repo/test-package@v2.0.0"
209
- ipvs , err := variablesources .NewInstalledPackageVariableSource (bundleList , bundleImage )
228
+ installedPackages , err := variablesources .MakeInstalledPackageVariables (
229
+ allBundles ,
230
+ []rukpakv1alpha1.BundleDeployment {
231
+ fakeBundleDeployment ("test-bd" , bundleImage ),
232
+ },
233
+ )
210
234
require .NoError (t , err )
211
235
212
- variables , err := ipvs .GetVariables (context .TODO ())
213
- require .NoError (t , err )
214
- require .Len (t , variables , 1 )
215
- packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
216
- assert .True (t , ok )
236
+ require .Len (t , installedPackages , 1 )
237
+ packageVariable := installedPackages [0 ]
217
238
assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
218
239
219
240
// ensure bundles are in version order (high to low)
@@ -227,14 +248,16 @@ func TestInstalledPackageVariableSource(t *testing.T) {
227
248
t .Run ("with zero major version" , func (t * testing.T ) {
228
249
t .Run ("with zero minor version" , func (t * testing.T ) {
229
250
const bundleImage = "registry.io/repo/test-package@v0.0.1"
230
- ipvs , err := variablesources .NewInstalledPackageVariableSource (bundleList , bundleImage )
251
+ installedPackages , err := variablesources .MakeInstalledPackageVariables (
252
+ allBundles ,
253
+ []rukpakv1alpha1.BundleDeployment {
254
+ fakeBundleDeployment ("test-bd" , bundleImage ),
255
+ },
256
+ )
231
257
require .NoError (t , err )
232
258
233
- variables , err := ipvs .GetVariables (context .TODO ())
234
- require .NoError (t , err )
235
- require .Len (t , variables , 1 )
236
- packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
237
- assert .True (t , ok )
259
+ require .Len (t , installedPackages , 1 )
260
+ packageVariable := installedPackages [0 ]
238
261
assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
239
262
240
263
// No upgrades are allowed in major version zero when minor version is also zero
@@ -245,14 +268,16 @@ func TestInstalledPackageVariableSource(t *testing.T) {
245
268
246
269
t .Run ("with non-zero minor version" , func (t * testing.T ) {
247
270
const bundleImage = "registry.io/repo/test-package@v0.1.0"
248
- ipvs , err := variablesources .NewInstalledPackageVariableSource (bundleList , bundleImage )
271
+ installedPackages , err := variablesources .MakeInstalledPackageVariables (
272
+ allBundles ,
273
+ []rukpakv1alpha1.BundleDeployment {
274
+ fakeBundleDeployment ("test-bd" , bundleImage ),
275
+ },
276
+ )
249
277
require .NoError (t , err )
250
278
251
- variables , err := ipvs .GetVariables (context .TODO ())
252
- require .NoError (t , err )
253
- require .Len (t , variables , 1 )
254
- packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
255
- assert .True (t , ok )
279
+ require .Len (t , installedPackages , 1 )
280
+ packageVariable := installedPackages [0 ]
256
281
assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
257
282
258
283
// Patch version upgrades are allowed, but not minor upgrades
@@ -268,14 +293,16 @@ func TestInstalledPackageVariableSource(t *testing.T) {
268
293
defer featuregatetesting .SetFeatureGateDuringTest (t , features .OperatorControllerFeatureGate , features .ForceSemverUpgradeConstraints , false )()
269
294
270
295
const bundleImage = "registry.io/repo/test-package@v2.0.0"
271
- ipvs , err := variablesources .NewInstalledPackageVariableSource (bundleList , bundleImage )
296
+ installedPackages , err := variablesources .MakeInstalledPackageVariables (
297
+ allBundles ,
298
+ []rukpakv1alpha1.BundleDeployment {
299
+ fakeBundleDeployment ("test-bd" , bundleImage ),
300
+ },
301
+ )
272
302
require .NoError (t , err )
273
303
274
- variables , err := ipvs .GetVariables (context .TODO ())
275
- require .NoError (t , err )
276
- require .Len (t , variables , 1 )
277
- packageVariable , ok := variables [0 ].(* olmvariables.InstalledPackageVariable )
278
- assert .True (t , ok )
304
+ require .Len (t , installedPackages , 1 )
305
+ packageVariable := installedPackages [0 ]
279
306
assert .Equal (t , deppy .IdentifierFromString ("installed package test-package" ), packageVariable .Identifier ())
280
307
281
308
// ensure bundles are in version order (high to low)
@@ -284,4 +311,16 @@ func TestInstalledPackageVariableSource(t *testing.T) {
284
311
assert .Equal (t , "test-package.v2.1.0" , packageVariable .Bundles ()[0 ].Name )
285
312
assert .Equal (t , "test-package.v2.0.0" , packageVariable .Bundles ()[1 ].Name )
286
313
})
314
+
315
+ t .Run ("installed bundle not found" , func (t * testing.T ) {
316
+ const bundleImage = "registry.io/repo/test-package@v9.0.0"
317
+ installedPackages , err := variablesources .MakeInstalledPackageVariables (
318
+ allBundles ,
319
+ []rukpakv1alpha1.BundleDeployment {
320
+ fakeBundleDeployment ("test-bd" , bundleImage ),
321
+ },
322
+ )
323
+ assert .Nil (t , installedPackages )
324
+ assert .ErrorContains (t , err , `bundleImage "registry.io/repo/test-package@v9.0.0" not found` )
325
+ })
287
326
}
0 commit comments