@@ -13,12 +13,8 @@ import (
13
13
"github.com/stretchr/testify/assert"
14
14
"github.com/stretchr/testify/require"
15
15
16
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
- "k8s.io/apimachinery/pkg/labels"
18
-
19
16
"github.com/operator-framework/api/pkg/constraints"
20
17
"github.com/operator-framework/api/pkg/operators/v1alpha1"
21
- listersv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
22
18
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
23
19
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver"
24
20
"github.com/operator-framework/operator-registry/pkg/api"
@@ -409,38 +405,10 @@ func TestSolveOperators_FindLatestVersionWithNestedDependencies(t *testing.T) {
409
405
assert .ElementsMatch (t , expected , operators )
410
406
}
411
407
412
- type stubCatalogSourceLister struct {
413
- catsrcs []* v1alpha1.CatalogSource
414
- namespace string
415
- }
408
+ type stubSourcePriorityProvider map [cache.SourceKey ]int
416
409
417
- func (l * stubCatalogSourceLister ) List (labels.Selector ) ([]* v1alpha1.CatalogSource , error ) {
418
- if l .namespace == "" {
419
- return l .catsrcs , nil
420
- }
421
- var result []* v1alpha1.CatalogSource
422
- for _ , cs := range l .catsrcs {
423
- if cs .Namespace == l .namespace {
424
- result = append (result , cs )
425
- }
426
- }
427
- return result , nil
428
- }
429
-
430
- func (l * stubCatalogSourceLister ) Get (name string ) (* v1alpha1.CatalogSource , error ) {
431
- for _ , cs := range l .catsrcs {
432
- if cs .Name == name {
433
- return cs , nil
434
- }
435
- }
436
- return nil , errors .New ("stub not found" )
437
- }
438
-
439
- func (l * stubCatalogSourceLister ) CatalogSources (namespace string ) listersv1alpha1.CatalogSourceNamespaceLister {
440
- return & stubCatalogSourceLister {
441
- catsrcs : l .catsrcs ,
442
- namespace : namespace ,
443
- }
410
+ func (spp stubSourcePriorityProvider ) Priority (k cache.SourceKey ) int {
411
+ return spp [k ]
444
412
}
445
413
446
414
func TestSolveOperators_CatsrcPrioritySorting (t * testing.T ) {
@@ -478,19 +446,7 @@ func TestSolveOperators_CatsrcPrioritySorting(t *testing.T) {
478
446
}
479
447
480
448
resolver := Resolver {
481
- cache : cache .New (ssp , cache .WithSourcePriorityProvider (catsrcPriorityProvider {lister : & stubCatalogSourceLister {
482
- catsrcs : []* v1alpha1.CatalogSource {
483
- {
484
- ObjectMeta : metav1.ObjectMeta {
485
- Namespace : "olm" ,
486
- Name : "high-priority-operator" ,
487
- },
488
- Spec : v1alpha1.CatalogSourceSpec {
489
- Priority : 100 ,
490
- },
491
- },
492
- },
493
- }})),
449
+ cache : cache .New (ssp , cache .WithSourcePriorityProvider (stubSourcePriorityProvider {cache.SourceKey {Namespace : "olm" , Name : "high-priority-operator" }: 100 })),
494
450
}
495
451
496
452
operators , err := resolver .Resolve ([]string {"olm" }, subs )
@@ -515,28 +471,10 @@ func TestSolveOperators_CatsrcPrioritySorting(t *testing.T) {
515
471
}
516
472
517
473
resolver = Resolver {
518
- cache : cache .New (ssp , cache .WithSourcePriorityProvider (catsrcPriorityProvider {lister : & stubCatalogSourceLister {
519
- catsrcs : []* v1alpha1.CatalogSource {
520
- {
521
- ObjectMeta : metav1.ObjectMeta {
522
- Namespace : "olm" ,
523
- Name : "high-priority-operator" ,
524
- },
525
- Spec : v1alpha1.CatalogSourceSpec {
526
- Priority : 100 ,
527
- },
528
- },
529
- {
530
- ObjectMeta : metav1.ObjectMeta {
531
- Namespace : "olm" ,
532
- Name : "community-operator" ,
533
- },
534
- Spec : v1alpha1.CatalogSourceSpec {
535
- Priority : 100 ,
536
- },
537
- },
538
- },
539
- }})),
474
+ cache : cache .New (ssp , cache .WithSourcePriorityProvider (stubSourcePriorityProvider {
475
+ cache.SourceKey {Namespace : "olm" , Name : "high-priority-operator" }: 100 ,
476
+ cache.SourceKey {Namespace : "olm" , Name : "community-operator" }: 100 ,
477
+ })),
540
478
}
541
479
542
480
operators , err = resolver .Resolve ([]string {"olm" }, subs )
0 commit comments