From f95c32ce3af0cd05f4de67af30d5981286e61bab Mon Sep 17 00:00:00 2001 From: dtfranz Date: Wed, 6 Sep 2023 16:53:41 -0700 Subject: [PATCH] Record InChannel information for bundles; add test for ProvidesGVK filter. Signed-off-by: dtfranz --- internal/catalogmetadata/predicates.go | 4 +-- internal/catalogmetadata/predicates_test.go | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/internal/catalogmetadata/predicates.go b/internal/catalogmetadata/predicates.go index 948a0ccf4..bd85a3cfa 100644 --- a/internal/catalogmetadata/predicates.go +++ b/internal/catalogmetadata/predicates.go @@ -3,8 +3,6 @@ package catalogmetadata import ( mmsemver "github.com/Masterminds/semver/v3" bsemver "github.com/blang/semver/v4" - - olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities" ) // TODO: Move somewhere nice. Probably into a ./predicates package @@ -54,7 +52,7 @@ func InChannel(channelName string) Predicate[Bundle] { } } -func ProvidesGVK(gvk *olmentity.GVK) Predicate[Bundle] { +func ProvidesGVK(gvk *GVK) Predicate[Bundle] { return func(bundle *Bundle) bool { providedGVKs, err := bundle.ProvidedGVKs() if err != nil { diff --git a/internal/catalogmetadata/predicates_test.go b/internal/catalogmetadata/predicates_test.go index 62901cf71..ab159fdbf 100644 --- a/internal/catalogmetadata/predicates_test.go +++ b/internal/catalogmetadata/predicates_test.go @@ -114,7 +114,33 @@ func TestInChannel(t *testing.T) { } func TestProvidesGVK(t *testing.T) { - // TODO: + b1 := &catalogmetadata.Bundle{Bundle: declcfg.Bundle{ + Properties: []property.Property{ + { + Type: property.TypeGVK, + Value: json.RawMessage(`[{"group":"foo.io","kind":"Foo","version":"v1"},{"group":"bar.io","kind":"Bar","version":"v1"}]`), + }, + }, + }} + b2 := &catalogmetadata.Bundle{Bundle: declcfg.Bundle{ + Properties: []property.Property{}, + }} + f1 := catalogmetadata.ProvidesGVK(&catalogmetadata.GVK{ + Group: "foo.io", + Version: "v1", + Kind: "Foo", + }) + f2 := catalogmetadata.ProvidesGVK(&catalogmetadata.GVK{ + Group: "baz.io", + Version: "v1alpha1", + Kind: "Baz", + }) + // Filter with Bundle which provides the GVK should return true + assert.True(t, f1(b1)) + // Filter with Bundle which does not provide the GVK should return false + assert.False(t, f2(b1)) + // Filter with Bundle with no GVK should return false + assert.False(t, f1(b2)) } func TestWithBundleImage(t *testing.T) {