Skip to content

Commit 8e98472

Browse files
committed
add package property to unit test cases
without this, some of the invariant checking was being missed by the unit tests Signed-off-by: Evan <[email protected]>
1 parent 1bea4b7 commit 8e98472

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

pkg/controller/registry/resolver/step_resolver_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package resolver
22

33
import (
4+
"fmt"
45
"strings"
56
"testing"
67
"time"
@@ -169,7 +170,7 @@ func TestResolver(t *testing.T) {
169170
{
170171
Path: "quay.io/test/bundle@sha256:abcd",
171172
Identifier: "b.v1",
172-
Properties: `{"properties":[{"type":"olm.gvk","value":{"group":"g","kind":"k","version":"v"}}]}`,
173+
Properties: `{"properties":[{"type":"olm.gvk","value":{"group":"g","kind":"k","version":"v"}},{"type":"olm.package","value":{"packageName":"b","version":"0.0.0"}}]}`,
173174
CatalogSourceRef: &corev1.ObjectReference{
174175
Namespace: catalog.Namespace,
175176
Name: catalog.Name,
@@ -349,7 +350,7 @@ func TestResolver(t *testing.T) {
349350
Path: "quay.io/test/bundle@sha256:abcd",
350351
Identifier: "a.v2",
351352
Replaces: "a.v1",
352-
Properties: `{"properties":[{"type":"olm.gvk","value":{"group":"g","kind":"k","version":"v"}}]}`,
353+
Properties: `{"properties":[{"type":"olm.gvk","value":{"group":"g","kind":"k","version":"v"}},{"type":"olm.package","value":{"packageName":"a","version":"0.0.0"}}]}`,
353354
CatalogSourceRef: &corev1.ObjectReference{
354355
Namespace: catalog.Namespace,
355356
Name: catalog.Name,
@@ -596,24 +597,14 @@ func TestResolver(t *testing.T) {
596597
}},
597598
out: resolverTestOut{
598599
steps: [][]*v1alpha1.Step{
599-
bundleSteps(bundle("a.v3", "a", "alpha", "a.v2", nil, nil, nil, nil), namespace, "a.v1", catalog),
600+
bundleSteps(bundle("a.v3", "a", "alpha", "a.v2", nil, nil, nil, nil, withVersion("1.0.0"), withSkipRange("< 1.0.0")), namespace, "a.v1", catalog),
600601
},
601602
subs: []*v1alpha1.Subscription{
602603
updatedSub(namespace, "a.v3", "a.v1", "a", "alpha", catalog),
603604
},
604605
},
605606
},
606607
{
607-
// This test uses logic that implements the FakeSourceQuerier to ensure
608-
// that the required API is provided by the new Operator.
609-
//
610-
// Background:
611-
// OLM used to add the new operator to the generation before removing
612-
// the old operator from the generation. The logic that removes an operator
613-
// from the current generation removes the APIs it provides from the list of
614-
// "available" APIs. This caused OLM to search for an operator that provides the API.
615-
// If the operator that provides the API uses a skipRange rather than the Spec.Replaces
616-
// field, the Replaces field is set to an empty string, causing OLM to fail to upgrade.
617608
name: "InstalledSubs/ExistingOperators/OldCSVsReplaced",
618609
clusterState: []runtime.Object{
619610
existingSub(namespace, "a.v1", "a", "alpha", catalog),
@@ -653,7 +644,7 @@ func TestResolver(t *testing.T) {
653644
}},
654645
out: resolverTestOut{
655646
steps: [][]*v1alpha1.Step{
656-
bundleSteps(bundle("a.v3", "a", "alpha", "", nil, nil, nil, nil), namespace, "a.v1", catalog),
647+
bundleSteps(bundle("a.v3", "a", "alpha", "", nil, nil, nil, nil, withVersion("1.0.0"), withSkipRange("< 1.0.0")), namespace, "a.v1", catalog),
657648
},
658649
subs: []*v1alpha1.Subscription{
659650
updatedSub(namespace, "a.v3", "a.v1", "a", "alpha", catalog),
@@ -691,7 +682,7 @@ func TestResolver(t *testing.T) {
691682
}},
692683
out: resolverTestOut{
693684
steps: [][]*v1alpha1.Step{
694-
bundleSteps(bundle("a.v3", "a", "alpha", "", nil, nil, nil, nil), namespace, "a.v1", catalog),
685+
bundleSteps(bundle("a.v3", "a", "alpha", "", nil, nil, nil, nil, withVersion("1.0.0"), withSkips([]string{"a.v1"})), namespace, "a.v1", catalog),
695686
},
696687
subs: []*v1alpha1.Subscription{
697688
updatedSub(namespace, "a.v3", "a.v1", "a", "alpha", catalog),

pkg/controller/registry/resolver/util_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ func apiSetToProperties(crds, apis APISet, deprecated bool) (out []*api.Property
261261
return
262262
}
263263

264+
func packageNameToProperty(packageName, version string) (out *api.Property) {
265+
val, err := json.Marshal(opregistry.PackageProperty{
266+
PackageName: packageName,
267+
Version: version,
268+
})
269+
if err != nil {
270+
panic(err)
271+
}
272+
273+
return &api.Property{
274+
Type: opregistry.PackageType,
275+
Value: string(val),
276+
}
277+
}
278+
264279
type bundleOpt func(*api.Bundle)
265280

266281
func withSkipRange(skipRange string) bundleOpt {
@@ -278,6 +293,13 @@ func withSkips(skips []string) bundleOpt {
278293
func withVersion(version string) bundleOpt {
279294
return func(b *api.Bundle) {
280295
b.Version = version
296+
props := b.GetProperties()
297+
for i, p := range props {
298+
if p.Type == opregistry.PackageType {
299+
props[i] = packageNameToProperty(b.PackageName, b.Version)
300+
}
301+
}
302+
b.Properties = props
281303
}
282304
}
283305

@@ -307,7 +329,9 @@ func bundle(name, pkg, channel, replaces string, providedCRDs, requiredCRDs, pro
307329
RequiredApis: apiSetToGVK(requiredCRDs, requiredAPIServices),
308330
Replaces: replaces,
309331
Dependencies: apiSetToDependencies(requiredCRDs, requiredAPIServices),
310-
Properties: apiSetToProperties(providedCRDs, providedAPIServices, false),
332+
Properties: append(apiSetToProperties(providedCRDs, providedAPIServices, false),
333+
packageNameToProperty(pkg, "0.0.0"),
334+
),
311335
}
312336
for _, f := range opts {
313337
f(b)

0 commit comments

Comments
 (0)