Skip to content

Commit fd81036

Browse files
committed
Add unit test to resolver for label dependency
Signed-off-by: Vu Dinh <[email protected]>
1 parent f3db0fa commit fd81036

File tree

1 file changed

+122
-6
lines changed

1 file changed

+122
-6
lines changed

pkg/controller/registry/resolver/resolver_test.go

Lines changed: 122 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,122 @@ func TestSolveOperators_WithGVKDependencies(t *testing.T) {
419419
}
420420
}
421421

422+
func TestSolveOperators_WithLabelDependencies(t *testing.T) {
423+
APISet := APISet{opregistry.APIKey{"g", "v", "k", "ks"}: struct{}{}}
424+
Provides := APISet
425+
426+
namespace := "olm"
427+
catalog := registry.CatalogKey{"community", namespace}
428+
429+
newSub := newSub(namespace, "packageA", "alpha", catalog)
430+
subs := []*v1alpha1.Subscription{newSub}
431+
432+
deps := []*api.Dependency{
433+
{
434+
Type: "olm.gvk",
435+
Value: `{"group":"g","kind":"k","version":"v"}`,
436+
},
437+
{
438+
Type: "olm.label",
439+
Value: `{"label":"lts"}`,
440+
},
441+
}
442+
443+
props := []*api.Property{
444+
{
445+
Type: "olm.label",
446+
Value: `{"label":"lts"}`,
447+
},
448+
}
449+
450+
operatorBv1 := genOperator("packageB.v1", "1.0.0", "", "packageB", "beta", "community", "olm", nil, Provides, nil, "")
451+
for _, p := range props {
452+
operatorBv1.properties = append(operatorBv1.properties, p)
453+
}
454+
455+
fakeNamespacedOperatorCache := NamespacedOperatorCache{
456+
snapshots: map[registry.CatalogKey]*CatalogSnapshot{
457+
registry.CatalogKey{
458+
Namespace: "olm",
459+
Name: "community",
460+
}: {
461+
key: registry.CatalogKey{
462+
Namespace: "olm",
463+
Name: "community",
464+
},
465+
operators: []*Operator{
466+
genOperator("packageA", "0.0.1", "", "packageA", "alpha", "community", "olm", nil, nil, deps, ""),
467+
operatorBv1,
468+
genOperator("packageB.v2", "2.0.0", "", "packageB", "alpha", "community", "olm", nil, Provides, nil, ""),
469+
},
470+
},
471+
},
472+
}
473+
satResolver := SatResolver{
474+
cache: getFakeOperatorCache(fakeNamespacedOperatorCache),
475+
}
476+
477+
operators, err := satResolver.SolveOperators([]string{"olm"}, nil, subs)
478+
assert.NoError(t, err)
479+
assert.Equal(t, 2, len(operators))
480+
481+
expected := OperatorSet{
482+
"packageA": genOperator("packageA", "0.0.1", "", "packageA", "alpha", "community", "olm", nil, nil, deps, ""),
483+
"packageB.v1": operatorBv1,
484+
}
485+
for k := range expected {
486+
require.NotNil(t, operators[k])
487+
assert.EqualValues(t, k, operators[k].Identifier())
488+
}
489+
}
490+
491+
func TestSolveOperators_WithUnsatisfiableLabelDependencies(t *testing.T) {
492+
APISet := APISet{opregistry.APIKey{"g", "v", "k", "ks"}: struct{}{}}
493+
Provides := APISet
494+
495+
namespace := "olm"
496+
catalog := registry.CatalogKey{"community", namespace}
497+
498+
newSub := newSub(namespace, "packageA", "alpha", catalog)
499+
subs := []*v1alpha1.Subscription{newSub}
500+
501+
deps := []*api.Dependency{
502+
{
503+
Type: "olm.gvk",
504+
Value: `{"group":"g","kind":"k","version":"v"}`,
505+
},
506+
{
507+
Type: "olm.label",
508+
Value: `{"label":"lts"}`,
509+
},
510+
}
511+
512+
fakeNamespacedOperatorCache := NamespacedOperatorCache{
513+
snapshots: map[registry.CatalogKey]*CatalogSnapshot{
514+
registry.CatalogKey{
515+
Namespace: "olm",
516+
Name: "community",
517+
}: {
518+
key: registry.CatalogKey{
519+
Namespace: "olm",
520+
Name: "community",
521+
},
522+
operators: []*Operator{
523+
genOperator("packageA", "0.0.1", "", "packageA", "alpha", "community", "olm", nil, nil, deps, ""),
524+
genOperator("packageB.v1", "1.0.0", "", "packageB", "alpha", "community", "olm", nil, Provides, nil, ""),
525+
},
526+
},
527+
},
528+
}
529+
satResolver := SatResolver{
530+
cache: getFakeOperatorCache(fakeNamespacedOperatorCache),
531+
}
532+
533+
operators, err := satResolver.SolveOperators([]string{"olm"}, nil, subs)
534+
assert.Error(t, err)
535+
assert.Equal(t, 0, len(operators))
536+
}
537+
422538
func TestSolveOperators_WithNestedGVKDependencies(t *testing.T) {
423539
APISet := APISet{opregistry.APIKey{"g", "v", "k", "ks"}: struct{}{}}
424540
Provides := APISet
@@ -596,7 +712,7 @@ func TestSolveOperators_PreferCatalogInSameNamespace(t *testing.T) {
596712

597713
csv := existingOperator(namespace, "packageA.v1", "packageA", "alpha", "", Provides, nil, nil, nil)
598714
csvs := []*v1alpha1.ClusterServiceVersion{csv}
599-
sub := existingSub(namespace,"packageA.v1", "packageA", "alpha", catalog)
715+
sub := existingSub(namespace, "packageA.v1", "packageA", "alpha", catalog)
600716
subs := []*v1alpha1.Subscription{sub}
601717

602718
fakeNamespacedOperatorCache := NamespacedOperatorCache{
@@ -789,7 +905,7 @@ func TestSolveOperators_SubscriptionlessOperatorsSatisfyDependencies(t *testing.
789905
assert.NoError(t, err)
790906
assert.Equal(t, 2, len(operators))
791907
expected := OperatorSet{
792-
"packageA.v1": stripBundle(genOperator("packageA.v1", "", "", "packageA", "alpha", "@existing", catalog.Namespace, nil, Provides, nil, "")),
908+
"packageA.v1": stripBundle(genOperator("packageA.v1", "", "", "packageA", "alpha", "@existing", catalog.Namespace, nil, Provides, nil, "")),
793909
"packageB.v1.0.1": genOperator("packageB.v1.0.1", "1.0.1", "packageB.v1.0.0", "packageB", "alpha", catalog.Name, catalog.Namespace, Provides, nil, apiSetToDependencies(Provides, nil), ""),
794910
}
795911
for k := range expected {
@@ -903,8 +1019,8 @@ func TestSolveOperators_TransferApiOwnership(t *testing.T) {
9031019
catalog := registry.CatalogKey{Name: "community", Namespace: namespace}
9041020

9051021
phases := []struct {
906-
subs []*v1alpha1.Subscription
907-
catalog *CatalogSnapshot
1022+
subs []*v1alpha1.Subscription
1023+
catalog *CatalogSnapshot
9081024
expected OperatorSet
9091025
}{
9101026
{
@@ -1023,7 +1139,7 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
10231139
Properties: apiSetToProperties(providedAPIs, nil),
10241140
},
10251141
dependencies: dependencies,
1026-
properties: apiSetToProperties(providedAPIs, nil),
1142+
properties: apiSetToProperties(providedAPIs, nil),
10271143
sourceInfo: &OperatorSourceInfo{
10281144
Catalog: registry.CatalogKey{
10291145
Name: catalogName,
@@ -1041,4 +1157,4 @@ func genOperator(name, version, replaces, pkg, channel, catalogName, catalogName
10411157
func stripBundle(o *Operator) *Operator {
10421158
o.bundle = nil
10431159
return o
1044-
}
1160+
}

0 commit comments

Comments
 (0)