4
4
"context"
5
5
"errors"
6
6
"io"
7
+ "io/fs"
7
8
"os"
8
9
"testing"
9
10
"testing/fstest"
@@ -26,8 +27,6 @@ import (
26
27
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
27
28
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
28
29
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
29
- "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
30
- "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
31
30
)
32
31
33
32
type mockPreflight struct {
@@ -197,8 +196,8 @@ func TestApply_Base(t *testing.T) {
197
196
t .Run ("fails trying to obtain an action client" , func (t * testing.T ) {
198
197
mockAcg := & mockActionGetter {actionClientForErr : errors .New ("failed getting action client" )}
199
198
helmApplier := applier.Helm {
200
- ActionClientGetter : mockAcg ,
201
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
199
+ ActionClientGetter : mockAcg ,
200
+ HelmChartLoader : noOpHelmChartLoader () ,
202
201
}
203
202
204
203
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -211,8 +210,8 @@ func TestApply_Base(t *testing.T) {
211
210
t .Run ("fails getting current release and !driver.ErrReleaseNotFound" , func (t * testing.T ) {
212
211
mockAcg := & mockActionGetter {getClientErr : errors .New ("failed getting current release" )}
213
212
helmApplier := applier.Helm {
214
- ActionClientGetter : mockAcg ,
215
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
213
+ ActionClientGetter : mockAcg ,
214
+ HelmChartLoader : noOpHelmChartLoader () ,
216
215
}
217
216
218
217
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -230,8 +229,8 @@ func TestApply_Installation(t *testing.T) {
230
229
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
231
230
}
232
231
helmApplier := applier.Helm {
233
- ActionClientGetter : mockAcg ,
234
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
232
+ ActionClientGetter : mockAcg ,
233
+ HelmChartLoader : noOpHelmChartLoader () ,
235
234
}
236
235
237
236
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -248,9 +247,9 @@ func TestApply_Installation(t *testing.T) {
248
247
}
249
248
mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
250
249
helmApplier := applier.Helm {
251
- ActionClientGetter : mockAcg ,
252
- Preflights : []applier.Preflight {mockPf },
253
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
250
+ ActionClientGetter : mockAcg ,
251
+ Preflights : []applier.Preflight {mockPf },
252
+ HelmChartLoader : noOpHelmChartLoader () ,
254
253
}
255
254
256
255
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -266,8 +265,8 @@ func TestApply_Installation(t *testing.T) {
266
265
installErr : errors .New ("failed installing chart" ),
267
266
}
268
267
helmApplier := applier.Helm {
269
- ActionClientGetter : mockAcg ,
270
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
268
+ ActionClientGetter : mockAcg ,
269
+ HelmChartLoader : noOpHelmChartLoader () ,
271
270
}
272
271
273
272
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -286,8 +285,8 @@ func TestApply_Installation(t *testing.T) {
286
285
},
287
286
}
288
287
helmApplier := applier.Helm {
289
- ActionClientGetter : mockAcg ,
290
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
288
+ ActionClientGetter : mockAcg ,
289
+ HelmChartLoader : noOpHelmChartLoader () ,
291
290
}
292
291
293
292
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -306,8 +305,8 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
306
305
dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
307
306
}
308
307
helmApplier := applier.Helm {
309
- ActionClientGetter : mockAcg ,
310
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
308
+ ActionClientGetter : mockAcg ,
309
+ HelmChartLoader : noOpHelmChartLoader () ,
311
310
}
312
311
313
312
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -328,10 +327,10 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
328
327
}
329
328
mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
330
329
helmApplier := applier.Helm {
331
- ActionClientGetter : mockAcg ,
332
- Preflights : []applier.Preflight {mockPf },
333
- PreAuthorizer : & mockPreAuthorizer {nil , nil },
334
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
330
+ ActionClientGetter : mockAcg ,
331
+ Preflights : []applier.Preflight {mockPf },
332
+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
333
+ HelmChartLoader : noOpHelmChartLoader () ,
335
334
}
336
335
337
336
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -350,9 +349,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
350
349
},
351
350
}
352
351
helmApplier := applier.Helm {
353
- ActionClientGetter : mockAcg ,
354
- PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
355
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
352
+ ActionClientGetter : mockAcg ,
353
+ PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
354
+ HelmChartLoader : noOpHelmChartLoader () ,
356
355
}
357
356
// Use a ClusterExtension with valid Spec fields.
358
357
validCE := & ocv1.ClusterExtension {
@@ -379,9 +378,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
379
378
},
380
379
}
381
380
helmApplier := applier.Helm {
382
- ActionClientGetter : mockAcg ,
383
- PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
384
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
381
+ ActionClientGetter : mockAcg ,
382
+ PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
383
+ HelmChartLoader : noOpHelmChartLoader () ,
385
384
}
386
385
// Use a ClusterExtension with valid Spec fields.
387
386
validCE := & ocv1.ClusterExtension {
@@ -408,9 +407,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
408
407
},
409
408
}
410
409
helmApplier := applier.Helm {
411
- ActionClientGetter : mockAcg ,
412
- PreAuthorizer : & mockPreAuthorizer {nil , nil },
413
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
410
+ ActionClientGetter : mockAcg ,
411
+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
412
+ HelmChartLoader : noOpHelmChartLoader () ,
414
413
}
415
414
416
415
// Use a ClusterExtension with valid Spec fields.
@@ -442,8 +441,8 @@ func TestApply_Upgrade(t *testing.T) {
442
441
dryRunUpgradeErr : errors .New ("failed attempting to dry-run upgrade chart" ),
443
442
}
444
443
helmApplier := applier.Helm {
445
- ActionClientGetter : mockAcg ,
446
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
444
+ ActionClientGetter : mockAcg ,
445
+ HelmChartLoader : noOpHelmChartLoader () ,
447
446
}
448
447
449
448
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -464,9 +463,9 @@ func TestApply_Upgrade(t *testing.T) {
464
463
}
465
464
mockPf := & mockPreflight {upgradeErr : errors .New ("failed during upgrade pre-flight check" )}
466
465
helmApplier := applier.Helm {
467
- ActionClientGetter : mockAcg ,
468
- Preflights : []applier.Preflight {mockPf },
469
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
466
+ ActionClientGetter : mockAcg ,
467
+ Preflights : []applier.Preflight {mockPf },
468
+ HelmChartLoader : noOpHelmChartLoader () ,
470
469
}
471
470
472
471
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -488,7 +487,7 @@ func TestApply_Upgrade(t *testing.T) {
488
487
mockPf := & mockPreflight {}
489
488
helmApplier := applier.Helm {
490
489
ActionClientGetter : mockAcg , Preflights : []applier.Preflight {mockPf },
491
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
490
+ HelmChartLoader : noOpHelmChartLoader () ,
492
491
}
493
492
494
493
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -509,9 +508,9 @@ func TestApply_Upgrade(t *testing.T) {
509
508
}
510
509
mockPf := & mockPreflight {}
511
510
helmApplier := applier.Helm {
512
- ActionClientGetter : mockAcg ,
513
- Preflights : []applier.Preflight {mockPf },
514
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
511
+ ActionClientGetter : mockAcg ,
512
+ Preflights : []applier.Preflight {mockPf },
513
+ HelmChartLoader : noOpHelmChartLoader () ,
515
514
}
516
515
517
516
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -530,8 +529,8 @@ func TestApply_Upgrade(t *testing.T) {
530
529
desiredRel : & testDesiredRelease ,
531
530
}
532
531
helmApplier := applier.Helm {
533
- ActionClientGetter : mockAcg ,
534
- BundleToHelmChartConverter : & convert. BundleToHelmChartConverter {} ,
532
+ ActionClientGetter : mockAcg ,
533
+ HelmChartLoader : noOpHelmChartLoader () ,
535
534
}
536
535
537
536
objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -556,8 +555,8 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
556
555
Manifest : validManifest ,
557
556
},
558
557
},
559
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
560
- fn : func (bundle source. BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
558
+ HelmChartLoader : fakeHelmChartLoader {
559
+ fn : func (bundleFS fs. FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
561
560
require .Equal (t , expectedWatchNamespace , watchNamespace )
562
561
return nil , nil
563
562
},
@@ -589,8 +588,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
589
588
Manifest : validManifest ,
590
589
},
591
590
},
592
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
593
- fn : func (bundle source. BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
591
+ HelmChartLoader : fakeHelmChartLoader {
592
+ fn : func (bundleFS fs. FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
594
593
require .Equal (t , expectedWatchNamespace , watchNamespace )
595
594
return nil , nil
596
595
},
@@ -609,8 +608,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
609
608
Manifest : validManifest ,
610
609
},
611
610
},
612
- BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
613
- fn : func (bundle source. BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
611
+ HelmChartLoader : fakeHelmChartLoader {
612
+ fn : func (bundleFS fs. FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
614
613
return nil , errors .New ("some error" )
615
614
},
616
615
},
@@ -621,10 +620,18 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
621
620
})
622
621
}
623
622
624
- type fakeBundleToHelmChartConverter struct {
625
- fn func (source.BundleSource , string , string ) (* chart.Chart , error )
623
+ func noOpHelmChartLoader () applier.HelmChartLoader {
624
+ return fakeHelmChartLoader {
625
+ fn : func (bundleFS fs.FS , _ string , _ string ) (* chart.Chart , error ) {
626
+ return nil , nil
627
+ },
628
+ }
629
+ }
630
+
631
+ type fakeHelmChartLoader struct {
632
+ fn func (fs.FS , string , string ) (* chart.Chart , error )
626
633
}
627
634
628
- func (f fakeBundleToHelmChartConverter ) ToHelmChart ( bundle source. BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
629
- return f .fn (bundle , installNamespace , watchNamespace )
635
+ func (f fakeHelmChartLoader ) Load ( bundleFS fs. FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
636
+ return f .fn (bundleFS , installNamespace , watchNamespace )
630
637
}
0 commit comments