44 "context"
55 "errors"
66 "io"
7- "io/fs"
87 "os"
98 "testing"
109 "testing/fstest"
@@ -27,6 +26,7 @@ import (
2726 "github.com/operator-framework/operator-controller/internal/operator-controller/applier"
2827 "github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
2928 "github.com/operator-framework/operator-controller/internal/operator-controller/features"
29+ "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
3030 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
3131)
3232
@@ -197,8 +197,8 @@ func TestApply_Base(t *testing.T) {
197197 t .Run ("fails trying to obtain an action client" , func (t * testing.T ) {
198198 mockAcg := & mockActionGetter {actionClientForErr : errors .New ("failed getting action client" )}
199199 helmApplier := applier.Helm {
200- ActionClientGetter : mockAcg ,
201- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
200+ ActionClientGetter : mockAcg ,
201+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
202202 }
203203
204204 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -211,8 +211,8 @@ func TestApply_Base(t *testing.T) {
211211 t .Run ("fails getting current release and !driver.ErrReleaseNotFound" , func (t * testing.T ) {
212212 mockAcg := & mockActionGetter {getClientErr : errors .New ("failed getting current release" )}
213213 helmApplier := applier.Helm {
214- ActionClientGetter : mockAcg ,
215- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
214+ ActionClientGetter : mockAcg ,
215+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
216216 }
217217
218218 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -230,8 +230,8 @@ func TestApply_Installation(t *testing.T) {
230230 dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
231231 }
232232 helmApplier := applier.Helm {
233- ActionClientGetter : mockAcg ,
234- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
233+ ActionClientGetter : mockAcg ,
234+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
235235 }
236236
237237 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -248,9 +248,9 @@ func TestApply_Installation(t *testing.T) {
248248 }
249249 mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
250250 helmApplier := applier.Helm {
251- ActionClientGetter : mockAcg ,
252- Preflights : []applier.Preflight {mockPf },
253- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
251+ ActionClientGetter : mockAcg ,
252+ Preflights : []applier.Preflight {mockPf },
253+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
254254 }
255255
256256 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -266,8 +266,8 @@ func TestApply_Installation(t *testing.T) {
266266 installErr : errors .New ("failed installing chart" ),
267267 }
268268 helmApplier := applier.Helm {
269- ActionClientGetter : mockAcg ,
270- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
269+ ActionClientGetter : mockAcg ,
270+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
271271 }
272272
273273 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -286,8 +286,8 @@ func TestApply_Installation(t *testing.T) {
286286 },
287287 }
288288 helmApplier := applier.Helm {
289- ActionClientGetter : mockAcg ,
290- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
289+ ActionClientGetter : mockAcg ,
290+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
291291 }
292292
293293 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -306,8 +306,8 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
306306 dryRunInstallErr : errors .New ("failed attempting to dry-run install chart" ),
307307 }
308308 helmApplier := applier.Helm {
309- ActionClientGetter : mockAcg ,
310- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
309+ ActionClientGetter : mockAcg ,
310+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
311311 }
312312
313313 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -328,10 +328,10 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
328328 }
329329 mockPf := & mockPreflight {installErr : errors .New ("failed during install pre-flight check" )}
330330 helmApplier := applier.Helm {
331- ActionClientGetter : mockAcg ,
332- Preflights : []applier.Preflight {mockPf },
333- PreAuthorizer : & mockPreAuthorizer {nil , nil },
334- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
331+ ActionClientGetter : mockAcg ,
332+ Preflights : []applier.Preflight {mockPf },
333+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
334+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
335335 }
336336
337337 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -350,9 +350,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
350350 },
351351 }
352352 helmApplier := applier.Helm {
353- ActionClientGetter : mockAcg ,
354- PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
355- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
353+ ActionClientGetter : mockAcg ,
354+ PreAuthorizer : & mockPreAuthorizer {nil , errPreAuth },
355+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
356356 }
357357 // Use a ClusterExtension with valid Spec fields.
358358 validCE := & ocv1.ClusterExtension {
@@ -379,9 +379,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
379379 },
380380 }
381381 helmApplier := applier.Helm {
382- ActionClientGetter : mockAcg ,
383- PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
384- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
382+ ActionClientGetter : mockAcg ,
383+ PreAuthorizer : & mockPreAuthorizer {missingRBAC , nil },
384+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
385385 }
386386 // Use a ClusterExtension with valid Spec fields.
387387 validCE := & ocv1.ClusterExtension {
@@ -408,9 +408,9 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
408408 },
409409 }
410410 helmApplier := applier.Helm {
411- ActionClientGetter : mockAcg ,
412- PreAuthorizer : & mockPreAuthorizer {nil , nil },
413- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
411+ ActionClientGetter : mockAcg ,
412+ PreAuthorizer : & mockPreAuthorizer {nil , nil },
413+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
414414 }
415415
416416 // Use a ClusterExtension with valid Spec fields.
@@ -442,8 +442,8 @@ func TestApply_Upgrade(t *testing.T) {
442442 dryRunUpgradeErr : errors .New ("failed attempting to dry-run upgrade chart" ),
443443 }
444444 helmApplier := applier.Helm {
445- ActionClientGetter : mockAcg ,
446- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
445+ ActionClientGetter : mockAcg ,
446+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
447447 }
448448
449449 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -464,9 +464,9 @@ func TestApply_Upgrade(t *testing.T) {
464464 }
465465 mockPf := & mockPreflight {upgradeErr : errors .New ("failed during upgrade pre-flight check" )}
466466 helmApplier := applier.Helm {
467- ActionClientGetter : mockAcg ,
468- Preflights : []applier.Preflight {mockPf },
469- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
467+ ActionClientGetter : mockAcg ,
468+ Preflights : []applier.Preflight {mockPf },
469+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
470470 }
471471
472472 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -488,7 +488,7 @@ func TestApply_Upgrade(t *testing.T) {
488488 mockPf := & mockPreflight {}
489489 helmApplier := applier.Helm {
490490 ActionClientGetter : mockAcg , Preflights : []applier.Preflight {mockPf },
491- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
491+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
492492 }
493493
494494 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -509,9 +509,9 @@ func TestApply_Upgrade(t *testing.T) {
509509 }
510510 mockPf := & mockPreflight {}
511511 helmApplier := applier.Helm {
512- ActionClientGetter : mockAcg ,
513- Preflights : []applier.Preflight {mockPf },
514- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
512+ ActionClientGetter : mockAcg ,
513+ Preflights : []applier.Preflight {mockPf },
514+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
515515 }
516516
517517 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -530,8 +530,8 @@ func TestApply_Upgrade(t *testing.T) {
530530 desiredRel : & testDesiredRelease ,
531531 }
532532 helmApplier := applier.Helm {
533- ActionClientGetter : mockAcg ,
534- BundleToHelmChartFn : convert .RegistryV1ToHelmChart ,
533+ ActionClientGetter : mockAcg ,
534+ BundleToHelmChartConverter : & convert.BundleToHelmChartConverter {} ,
535535 }
536536
537537 objs , state , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
@@ -556,9 +556,11 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
556556 Manifest : validManifest ,
557557 },
558558 },
559- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
560- require .Equal (t , expectedWatchNamespace , watchNamespace )
561- return convert .RegistryV1ToHelmChart (rv1 , installNamespace , watchNamespace )
559+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
560+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
561+ require .Equal (t , expectedWatchNamespace , watchNamespace )
562+ return nil , nil
563+ },
562564 },
563565 }
564566
@@ -587,9 +589,11 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
587589 Manifest : validManifest ,
588590 },
589591 },
590- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
591- require .Equal (t , expectedWatchNamespace , watchNamespace )
592- return convert .RegistryV1ToHelmChart (rv1 , installNamespace , watchNamespace )
592+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
593+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
594+ require .Equal (t , expectedWatchNamespace , watchNamespace )
595+ return nil , nil
596+ },
593597 },
594598 }
595599
@@ -605,12 +609,22 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
605609 Manifest : validManifest ,
606610 },
607611 },
608- BundleToHelmChartFn : func (rv1 fs.FS , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
609- return nil , errors .New ("some error" )
612+ BundleToHelmChartConverter : & fakeBundleToHelmChartConverter {
613+ fn : func (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
614+ return nil , errors .New ("some error" )
615+ },
610616 },
611617 }
612618
613619 _ , _ , err := helmApplier .Apply (context .TODO (), validFS , testCE , testObjectLabels , testStorageLabels )
614620 require .Error (t , err )
615621 })
616622}
623+
624+ type fakeBundleToHelmChartConverter struct {
625+ fn func (source.BundleSource , string , string ) (* chart.Chart , error )
626+ }
627+
628+ func (f fakeBundleToHelmChartConverter ) ToHelmChart (bundle source.BundleSource , installNamespace string , watchNamespace string ) (* chart.Chart , error ) {
629+ return f .fn (bundle , installNamespace , watchNamespace )
630+ }
0 commit comments