@@ -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"
@@ -422,38 +418,10 @@ func TestSolveOperators_FindLatestVersionWithNestedDependencies(t *testing.T) {
422
418
}
423
419
}
424
420
425
- type stubCatalogSourceLister struct {
426
- catsrcs []* v1alpha1.CatalogSource
427
- namespace string
428
- }
421
+ type stubSourcePriorityProvider map [cache.SourceKey ]int
429
422
430
- func (l * stubCatalogSourceLister ) List (labels.Selector ) ([]* v1alpha1.CatalogSource , error ) {
431
- if l .namespace == "" {
432
- return l .catsrcs , nil
433
- }
434
- var result []* v1alpha1.CatalogSource
435
- for _ , cs := range l .catsrcs {
436
- if cs .Namespace == l .namespace {
437
- result = append (result , cs )
438
- }
439
- }
440
- return result , nil
441
- }
442
-
443
- func (l * stubCatalogSourceLister ) Get (name string ) (* v1alpha1.CatalogSource , error ) {
444
- for _ , cs := range l .catsrcs {
445
- if cs .Name == name {
446
- return cs , nil
447
- }
448
- }
449
- return nil , errors .New ("stub not found" )
450
- }
451
-
452
- func (l * stubCatalogSourceLister ) CatalogSources (namespace string ) listersv1alpha1.CatalogSourceNamespaceLister {
453
- return & stubCatalogSourceLister {
454
- catsrcs : l .catsrcs ,
455
- namespace : namespace ,
456
- }
423
+ func (spp stubSourcePriorityProvider ) Priority (k cache.SourceKey ) int {
424
+ return spp [k ]
457
425
}
458
426
459
427
func TestSolveOperators_CatsrcPrioritySorting (t * testing.T ) {
@@ -491,19 +459,7 @@ func TestSolveOperators_CatsrcPrioritySorting(t *testing.T) {
491
459
}
492
460
493
461
satResolver := SatResolver {
494
- cache : cache .New (ssp , cache .WithSourcePriorityProvider (catsrcPriorityProvider {lister : & stubCatalogSourceLister {
495
- catsrcs : []* v1alpha1.CatalogSource {
496
- {
497
- ObjectMeta : metav1.ObjectMeta {
498
- Namespace : "olm" ,
499
- Name : "high-priority-operator" ,
500
- },
501
- Spec : v1alpha1.CatalogSourceSpec {
502
- Priority : 100 ,
503
- },
504
- },
505
- },
506
- }})),
462
+ cache : cache .New (ssp , cache .WithSourcePriorityProvider (stubSourcePriorityProvider {cache.SourceKey {Namespace : "olm" , Name : "high-priority-operator" }: 100 })),
507
463
}
508
464
509
465
operators , err := satResolver .SolveOperators ([]string {"olm" }, subs )
@@ -531,28 +487,10 @@ func TestSolveOperators_CatsrcPrioritySorting(t *testing.T) {
531
487
}
532
488
533
489
satResolver = SatResolver {
534
- cache : cache .New (ssp , cache .WithSourcePriorityProvider (catsrcPriorityProvider {lister : & stubCatalogSourceLister {
535
- catsrcs : []* v1alpha1.CatalogSource {
536
- {
537
- ObjectMeta : metav1.ObjectMeta {
538
- Namespace : "olm" ,
539
- Name : "high-priority-operator" ,
540
- },
541
- Spec : v1alpha1.CatalogSourceSpec {
542
- Priority : 100 ,
543
- },
544
- },
545
- {
546
- ObjectMeta : metav1.ObjectMeta {
547
- Namespace : "olm" ,
548
- Name : "community-operator" ,
549
- },
550
- Spec : v1alpha1.CatalogSourceSpec {
551
- Priority : 100 ,
552
- },
553
- },
554
- },
555
- }})),
490
+ cache : cache .New (ssp , cache .WithSourcePriorityProvider (stubSourcePriorityProvider {
491
+ cache.SourceKey {Namespace : "olm" , Name : "high-priority-operator" }: 100 ,
492
+ cache.SourceKey {Namespace : "olm" , Name : "community-operator" }: 100 ,
493
+ })),
556
494
}
557
495
558
496
operators , err = satResolver .SolveOperators ([]string {"olm" }, subs )
0 commit comments