1
- package convert
1
+ package convert_test
2
2
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/operator-framework/operator-controller/internal/rukpak/convert"
6
7
"os"
7
8
"strings"
8
9
"testing"
@@ -49,22 +50,22 @@ func getCsvAndService() (v1alpha1.ClusterServiceVersion, corev1.Service) {
49
50
func TestRegistryV1SuiteNamespaceNotAvailable (t * testing.T ) {
50
51
var targetNamespaces []string
51
52
52
- t .Log ("RegistryV1 Suite Convert" )
53
+ t .Log ("convert. RegistryV1 Suite Convert" )
53
54
t .Log ("It should set the namespaces of the object correctly" )
54
55
t .Log ("It should set the namespace to installnamespace if not available" )
55
56
56
57
t .Log ("By creating a registry v1 bundle" )
57
58
csv , svc := getCsvAndService ()
58
59
59
60
unstructuredSvc := convertToUnstructured (t , svc )
60
- registryv1Bundle := RegistryV1 {
61
+ registryv1Bundle := convert. RegistryV1 {
61
62
PackageName : "testPkg" ,
62
63
CSV : csv ,
63
64
Others : []unstructured.Unstructured {unstructuredSvc },
64
65
}
65
66
66
67
t .Log ("By converting to plain" )
67
- plainBundle , err := Convert (registryv1Bundle , installNamespace , targetNamespaces )
68
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , targetNamespaces )
68
69
require .NoError (t , err )
69
70
70
71
t .Log ("By verifying if plain bundle has required objects" )
@@ -80,7 +81,7 @@ func TestRegistryV1SuiteNamespaceNotAvailable(t *testing.T) {
80
81
func TestRegistryV1SuiteNamespaceAvailable (t * testing.T ) {
81
82
var targetNamespaces []string
82
83
83
- t .Log ("RegistryV1 Suite Convert" )
84
+ t .Log ("convert. RegistryV1 Suite Convert" )
84
85
t .Log ("It should set the namespaces of the object correctly" )
85
86
t .Log ("It should override namespace if already available" )
86
87
@@ -91,14 +92,14 @@ func TestRegistryV1SuiteNamespaceAvailable(t *testing.T) {
91
92
unstructuredSvc := convertToUnstructured (t , svc )
92
93
unstructuredSvc .SetGroupVersionKind (schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "Service" })
93
94
94
- registryv1Bundle := RegistryV1 {
95
+ registryv1Bundle := convert. RegistryV1 {
95
96
PackageName : "testPkg" ,
96
97
CSV : csv ,
97
98
Others : []unstructured.Unstructured {unstructuredSvc },
98
99
}
99
100
100
101
t .Log ("By converting to plain" )
101
- plainBundle , err := Convert (registryv1Bundle , installNamespace , targetNamespaces )
102
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , targetNamespaces )
102
103
require .NoError (t , err )
103
104
104
105
t .Log ("By verifying if plain bundle has required objects" )
@@ -114,7 +115,7 @@ func TestRegistryV1SuiteNamespaceAvailable(t *testing.T) {
114
115
func TestRegistryV1SuiteNamespaceUnsupportedKind (t * testing.T ) {
115
116
var targetNamespaces []string
116
117
117
- t .Log ("RegistryV1 Suite Convert" )
118
+ t .Log ("convert. RegistryV1 Suite Convert" )
118
119
t .Log ("It should set the namespaces of the object correctly" )
119
120
t .Log ("It should error when object is not supported" )
120
121
t .Log ("It should error when unsupported GVK is passed" )
@@ -132,14 +133,14 @@ func TestRegistryV1SuiteNamespaceUnsupportedKind(t *testing.T) {
132
133
unstructuredEvt := convertToUnstructured (t , event )
133
134
unstructuredEvt .SetGroupVersionKind (schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "Event" })
134
135
135
- registryv1Bundle := RegistryV1 {
136
+ registryv1Bundle := convert. RegistryV1 {
136
137
PackageName : "testPkg" ,
137
138
CSV : csv ,
138
139
Others : []unstructured.Unstructured {unstructuredEvt },
139
140
}
140
141
141
142
t .Log ("By converting to plain" )
142
- plainBundle , err := Convert (registryv1Bundle , installNamespace , targetNamespaces )
143
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , targetNamespaces )
143
144
require .Error (t , err )
144
145
require .ErrorContains (t , err , "bundle contains unsupported resource" )
145
146
require .Nil (t , plainBundle )
@@ -148,7 +149,7 @@ func TestRegistryV1SuiteNamespaceUnsupportedKind(t *testing.T) {
148
149
func TestRegistryV1SuiteNamespaceClusterScoped (t * testing.T ) {
149
150
var targetNamespaces []string
150
151
151
- t .Log ("RegistryV1 Suite Convert" )
152
+ t .Log ("convert. RegistryV1 Suite Convert" )
152
153
t .Log ("It should set the namespaces of the object correctly" )
153
154
t .Log ("It should not set ns cluster scoped object is passed" )
154
155
t .Log ("It should not error when cluster scoped obj is passed and not set its namespace" )
@@ -166,14 +167,14 @@ func TestRegistryV1SuiteNamespaceClusterScoped(t *testing.T) {
166
167
unstructuredpriorityclass := convertToUnstructured (t , pc )
167
168
unstructuredpriorityclass .SetGroupVersionKind (schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "PriorityClass" })
168
169
169
- registryv1Bundle := RegistryV1 {
170
+ registryv1Bundle := convert. RegistryV1 {
170
171
PackageName : "testPkg" ,
171
172
CSV : csv ,
172
173
Others : []unstructured.Unstructured {unstructuredpriorityclass },
173
174
}
174
175
175
176
t .Log ("By converting to plain" )
176
- plainBundle , err := Convert (registryv1Bundle , installNamespace , targetNamespaces )
177
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , targetNamespaces )
177
178
require .NoError (t , err )
178
179
179
180
t .Log ("By verifying if plain bundle has required objects" )
@@ -242,7 +243,7 @@ func getBaseCsvAndService() (v1alpha1.ClusterServiceVersion, corev1.Service) {
242
243
}
243
244
244
245
func TestRegistryV1SuiteGenerateAllNamespace (t * testing.T ) {
245
- t .Log ("RegistryV1 Suite Convert" )
246
+ t .Log ("convert. RegistryV1 Suite Convert" )
246
247
t .Log ("It should generate objects successfully based on target namespaces" )
247
248
248
249
t .Log ("It should convert into plain manifests successfully with AllNamespaces" )
@@ -253,14 +254,14 @@ func TestRegistryV1SuiteGenerateAllNamespace(t *testing.T) {
253
254
t .Log ("By creating a registry v1 bundle" )
254
255
watchNamespaces := []string {"" }
255
256
unstructuredSvc := convertToUnstructured (t , svc )
256
- registryv1Bundle := RegistryV1 {
257
+ registryv1Bundle := convert. RegistryV1 {
257
258
PackageName : "testPkg" ,
258
259
CSV : * csv ,
259
260
Others : []unstructured.Unstructured {unstructuredSvc },
260
261
}
261
262
262
263
t .Log ("By converting to plain" )
263
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
264
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
264
265
require .NoError (t , err )
265
266
266
267
t .Log ("By verifying if plain bundle has required objects" )
@@ -275,7 +276,7 @@ func TestRegistryV1SuiteGenerateAllNamespace(t *testing.T) {
275
276
}
276
277
277
278
func TestRegistryV1SuiteGenerateMultiNamespace (t * testing.T ) {
278
- t .Log ("RegistryV1 Suite Convert" )
279
+ t .Log ("convert. RegistryV1 Suite Convert" )
279
280
t .Log ("It should generate objects successfully based on target namespaces" )
280
281
281
282
t .Log ("It should convert into plain manifests successfully with MultiNamespace" )
@@ -286,14 +287,14 @@ func TestRegistryV1SuiteGenerateMultiNamespace(t *testing.T) {
286
287
t .Log ("By creating a registry v1 bundle" )
287
288
watchNamespaces := []string {"testWatchNs1" , "testWatchNs2" }
288
289
unstructuredSvc := convertToUnstructured (t , svc )
289
- registryv1Bundle := RegistryV1 {
290
+ registryv1Bundle := convert. RegistryV1 {
290
291
PackageName : "testPkg" ,
291
292
CSV : * csv ,
292
293
Others : []unstructured.Unstructured {unstructuredSvc },
293
294
}
294
295
295
296
t .Log ("By converting to plain" )
296
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
297
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
297
298
require .NoError (t , err )
298
299
299
300
t .Log ("By verifying if plain bundle has required objects" )
@@ -308,7 +309,7 @@ func TestRegistryV1SuiteGenerateMultiNamespace(t *testing.T) {
308
309
}
309
310
310
311
func TestRegistryV1SuiteGenerateSingleNamespace (t * testing.T ) {
311
- t .Log ("RegistryV1 Suite Convert" )
312
+ t .Log ("convert. RegistryV1 Suite Convert" )
312
313
t .Log ("It should generate objects successfully based on target namespaces" )
313
314
314
315
t .Log ("It should convert into plain manifests successfully with SingleNamespace" )
@@ -319,14 +320,14 @@ func TestRegistryV1SuiteGenerateSingleNamespace(t *testing.T) {
319
320
t .Log ("By creating a registry v1 bundle" )
320
321
watchNamespaces := []string {"testWatchNs1" }
321
322
unstructuredSvc := convertToUnstructured (t , svc )
322
- registryv1Bundle := RegistryV1 {
323
+ registryv1Bundle := convert. RegistryV1 {
323
324
PackageName : "testPkg" ,
324
325
CSV : * csv ,
325
326
Others : []unstructured.Unstructured {unstructuredSvc },
326
327
}
327
328
328
329
t .Log ("By converting to plain" )
329
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
330
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
330
331
require .NoError (t , err )
331
332
332
333
t .Log ("By verifying if plain bundle has required objects" )
@@ -341,7 +342,7 @@ func TestRegistryV1SuiteGenerateSingleNamespace(t *testing.T) {
341
342
}
342
343
343
344
func TestRegistryV1SuiteGenerateOwnNamespace (t * testing.T ) {
344
- t .Log ("RegistryV1 Suite Convert" )
345
+ t .Log ("convert. RegistryV1 Suite Convert" )
345
346
t .Log ("It should generate objects successfully based on target namespaces" )
346
347
347
348
t .Log ("It should convert into plain manifests successfully with own namespace" )
@@ -352,14 +353,14 @@ func TestRegistryV1SuiteGenerateOwnNamespace(t *testing.T) {
352
353
t .Log ("By creating a registry v1 bundle" )
353
354
watchNamespaces := []string {installNamespace }
354
355
unstructuredSvc := convertToUnstructured (t , svc )
355
- registryv1Bundle := RegistryV1 {
356
+ registryv1Bundle := convert. RegistryV1 {
356
357
PackageName : "testPkg" ,
357
358
CSV : * csv ,
358
359
Others : []unstructured.Unstructured {unstructuredSvc },
359
360
}
360
361
361
362
t .Log ("By converting to plain" )
362
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
363
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
363
364
require .NoError (t , err )
364
365
365
366
t .Log ("By verifying if plain bundle has required objects" )
@@ -374,7 +375,7 @@ func TestRegistryV1SuiteGenerateOwnNamespace(t *testing.T) {
374
375
}
375
376
376
377
func TestRegistryV1SuiteGenerateErrorMultiNamespaceEmpty (t * testing.T ) {
377
- t .Log ("RegistryV1 Suite Convert" )
378
+ t .Log ("convert. RegistryV1 Suite Convert" )
378
379
t .Log ("It should generate objects successfully based on target namespaces" )
379
380
380
381
t .Log ("It should error when multinamespace mode is supported with an empty string in target namespaces" )
@@ -385,20 +386,20 @@ func TestRegistryV1SuiteGenerateErrorMultiNamespaceEmpty(t *testing.T) {
385
386
t .Log ("By creating a registry v1 bundle" )
386
387
watchNamespaces := []string {"testWatchNs1" , "" }
387
388
unstructuredSvc := convertToUnstructured (t , svc )
388
- registryv1Bundle := RegistryV1 {
389
+ registryv1Bundle := convert. RegistryV1 {
389
390
PackageName : "testPkg" ,
390
391
CSV : * csv ,
391
392
Others : []unstructured.Unstructured {unstructuredSvc },
392
393
}
393
394
394
395
t .Log ("By converting to plain" )
395
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
396
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
396
397
require .Error (t , err )
397
398
require .Nil (t , plainBundle )
398
399
}
399
400
400
401
func TestRegistryV1SuiteGenerateErrorSingleNamespaceDisabled (t * testing.T ) {
401
- t .Log ("RegistryV1 Suite Convert" )
402
+ t .Log ("convert. RegistryV1 Suite Convert" )
402
403
t .Log ("It should generate objects successfully based on target namespaces" )
403
404
404
405
t .Log ("It should error when single namespace mode is disabled with more than one target namespaces" )
@@ -409,20 +410,20 @@ func TestRegistryV1SuiteGenerateErrorSingleNamespaceDisabled(t *testing.T) {
409
410
t .Log ("By creating a registry v1 bundle" )
410
411
watchNamespaces := []string {"testWatchNs1" , "testWatchNs2" }
411
412
unstructuredSvc := convertToUnstructured (t , svc )
412
- registryv1Bundle := RegistryV1 {
413
+ registryv1Bundle := convert. RegistryV1 {
413
414
PackageName : "testPkg" ,
414
415
CSV : * csv ,
415
416
Others : []unstructured.Unstructured {unstructuredSvc },
416
417
}
417
418
418
419
t .Log ("By converting to plain" )
419
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
420
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
420
421
require .Error (t , err )
421
422
require .Nil (t , plainBundle )
422
423
}
423
424
424
425
func TestRegistryV1SuiteGenerateErrorAllNamespaceDisabled (t * testing.T ) {
425
- t .Log ("RegistryV1 Suite Convert" )
426
+ t .Log ("convert. RegistryV1 Suite Convert" )
426
427
t .Log ("It should generate objects successfully based on target namespaces" )
427
428
428
429
t .Log ("It should error when all namespace mode is disabled with target namespace containing an empty string" )
@@ -438,50 +439,26 @@ func TestRegistryV1SuiteGenerateErrorAllNamespaceDisabled(t *testing.T) {
438
439
t .Log ("By creating a registry v1 bundle" )
439
440
watchNamespaces := []string {"" }
440
441
unstructuredSvc := convertToUnstructured (t , svc )
441
- registryv1Bundle := RegistryV1 {
442
+ registryv1Bundle := convert. RegistryV1 {
442
443
PackageName : "testPkg" ,
443
444
CSV : * csv ,
444
445
Others : []unstructured.Unstructured {unstructuredSvc },
445
446
}
446
447
447
448
t .Log ("By converting to plain" )
448
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
449
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
449
450
require .Error (t , err )
450
451
require .Nil (t , plainBundle )
451
452
}
452
453
453
- func TestRegistryV1SuiteGeneratePropagateCsvAnnotations (t * testing.T ) {
454
- t .Log ("RegistryV1 Suite Convert" )
455
- t .Log ("It should generate objects successfully based on target namespaces" )
456
-
457
- t .Log ("It should propagate csv annotations to chart metadata annotation" )
458
- baseCSV , svc := getBaseCsvAndService ()
459
- csv := baseCSV .DeepCopy ()
460
- csv .Spec .InstallModes = []v1alpha1.InstallMode {{Type : v1alpha1 .InstallModeTypeMultiNamespace , Supported : true }}
461
-
462
- t .Log ("By creating a registry v1 bundle" )
463
- watchNamespaces := []string {"testWatchNs1" , "testWatchNs2" }
464
- unstructuredSvc := convertToUnstructured (t , svc )
465
- registryv1Bundle := RegistryV1 {
466
- PackageName : "testPkg" ,
467
- CSV : * csv ,
468
- Others : []unstructured.Unstructured {unstructuredSvc },
469
- }
470
-
471
- t .Log ("By converting to helm" )
472
- chrt , err := toChart (registryv1Bundle , installNamespace , watchNamespaces )
473
- require .NoError (t , err )
474
- require .Contains (t , chrt .Metadata .Annotations , olmProperties )
475
- }
476
-
477
454
func TestRegistryV1SuiteReadBundleFileSystem (t * testing.T ) {
478
- t .Log ("RegistryV1 Suite Convert" )
455
+ t .Log ("convert. RegistryV1 Suite Convert" )
479
456
t .Log ("It should generate objects successfully based on target namespaces" )
480
457
481
458
t .Log ("It should read the registry+v1 bundle filesystem correctly" )
482
459
t .Log ("It should include metadata/properties.yaml and csv.metadata.annotations['olm.properties'] in chart metadata" )
483
460
fsys := os .DirFS ("testdata/combine-properties-bundle" )
484
- chrt , err := RegistryV1ToHelmChart (context .Background (), fsys , "" , nil )
461
+ chrt , err := convert . RegistryV1ToHelmChart (context .Background (), fsys , "" , nil )
485
462
require .NoError (t , err )
486
463
require .NotNil (t , chrt )
487
464
require .NotNil (t , chrt .Metadata )
@@ -490,7 +467,7 @@ func TestRegistryV1SuiteReadBundleFileSystem(t *testing.T) {
490
467
}
491
468
492
469
func TestRegistryV1SuiteGenerateNoWebhooks (t * testing.T ) {
493
- t .Log ("RegistryV1 Suite Convert" )
470
+ t .Log ("convert. RegistryV1 Suite Convert" )
494
471
t .Log ("It should generate objects successfully based on target namespaces" )
495
472
496
473
t .Log ("It should enforce limitations" )
@@ -506,20 +483,20 @@ func TestRegistryV1SuiteGenerateNoWebhooks(t *testing.T) {
506
483
},
507
484
}
508
485
watchNamespaces := []string {metav1 .NamespaceAll }
509
- registryv1Bundle := RegistryV1 {
486
+ registryv1Bundle := convert. RegistryV1 {
510
487
PackageName : "testPkg" ,
511
488
CSV : csv ,
512
489
}
513
490
514
491
t .Log ("By converting to plain" )
515
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
492
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
516
493
require .Error (t , err )
517
494
require .ErrorContains (t , err , "webhookDefinitions are not supported" )
518
495
require .Nil (t , plainBundle )
519
496
}
520
497
521
498
func TestRegistryV1SuiteGenerateNoAPISerciceDefinitions (t * testing.T ) {
522
- t .Log ("RegistryV1 Suite Convert" )
499
+ t .Log ("convert. RegistryV1 Suite Convert" )
523
500
t .Log ("It should generate objects successfully based on target namespaces" )
524
501
525
502
t .Log ("It should enforce limitations" )
@@ -537,13 +514,13 @@ func TestRegistryV1SuiteGenerateNoAPISerciceDefinitions(t *testing.T) {
537
514
},
538
515
}
539
516
watchNamespaces := []string {metav1 .NamespaceAll }
540
- registryv1Bundle := RegistryV1 {
517
+ registryv1Bundle := convert. RegistryV1 {
541
518
PackageName : "testPkg" ,
542
519
CSV : csv ,
543
520
}
544
521
545
522
t .Log ("By converting to plain" )
546
- plainBundle , err := Convert (registryv1Bundle , installNamespace , watchNamespaces )
523
+ plainBundle , err := convert . Convert (registryv1Bundle , installNamespace , watchNamespaces )
547
524
require .Error (t , err )
548
525
require .ErrorContains (t , err , "apiServiceDefintions are not supported" )
549
526
require .Nil (t , plainBundle )
@@ -559,7 +536,7 @@ func convertToUnstructured(t *testing.T, obj interface{}) unstructured.Unstructu
559
536
func findObjectByName (name string , result []client.Object ) client.Object {
560
537
for _ , o := range result {
561
538
// Since this is a controlled env, comparing only the names is sufficient for now.
562
- // In future, compare GVKs too by ensuring its set on the unstructuredObj.
539
+ // In the future, compare GVKs too by ensuring its set on the unstructuredObj.
563
540
if o .GetName () == name {
564
541
return o
565
542
}
0 commit comments