From c32e396e5fae8ba81f4efd27fbe3c0d86ceb0190 Mon Sep 17 00:00:00 2001 From: akihikokuroda Date: Sun, 16 Jan 2022 14:25:11 -0500 Subject: [PATCH] adding properties to package and channel Signed-off-by: akihikokuroda --- alpha/action/render_test.go | 19 +++++++++-- .../foo-index-v0.2.0-declcfg/foo/index.yaml | 10 ++++++ alpha/declcfg/declcfg.go | 20 ++++++------ alpha/declcfg/declcfg_to_model_test.go | 32 +++++++++++++++++++ alpha/declcfg/helpers_test.go | 10 ++++++ 5 files changed, 80 insertions(+), 11 deletions(-) diff --git a/alpha/action/render_test.go b/alpha/action/render_test.go index b355233ec..e36872a89 100644 --- a/alpha/action/render_test.go +++ b/alpha/action/render_test.go @@ -3,6 +3,7 @@ package action_test import ( "context" "embed" + "encoding/json" "errors" "io/fs" "os" @@ -265,13 +266,20 @@ func TestRender(t *testing.T) { Schema: "olm.package", Name: "foo", DefaultChannel: "beta", + Properties: []property.Property{ + {Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")}, + }, }, }, Channels: []declcfg.Channel{ {Schema: "olm.channel", Package: "foo", Name: "beta", Entries: []declcfg.ChannelEntry{ {Name: "foo.v0.1.0", SkipRange: "<0.1.0"}, {Name: "foo.v0.2.0", Replaces: "foo.v0.1.0", SkipRange: "<0.2.0", Skips: []string{"foo.v0.1.1", "foo.v0.1.2"}}, - }}, + }, + Properties: []property.Property{ + {Type: "user", Value: json.RawMessage("{\"group\":\"xyz.com\",\"name\":\"account\"}")}, + }, + }, {Schema: "olm.channel", Package: "foo", Name: "stable", Entries: []declcfg.ChannelEntry{ {Name: "foo.v0.2.0", Replaces: "foo.v0.1.0", SkipRange: "<0.2.0", Skips: []string{"foo.v0.1.1", "foo.v0.1.2"}}, }}, @@ -356,13 +364,20 @@ func TestRender(t *testing.T) { Schema: "olm.package", Name: "foo", DefaultChannel: "beta", + Properties: []property.Property{ + {Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")}, + }, }, }, Channels: []declcfg.Channel{ {Schema: "olm.channel", Package: "foo", Name: "beta", Entries: []declcfg.ChannelEntry{ {Name: "foo.v0.1.0", SkipRange: "<0.1.0"}, {Name: "foo.v0.2.0", Replaces: "foo.v0.1.0", SkipRange: "<0.2.0", Skips: []string{"foo.v0.1.1", "foo.v0.1.2"}}, - }}, + }, + Properties: []property.Property{ + {Type: "user", Value: json.RawMessage("{\"group\":\"xyz.com\",\"name\":\"account\"}")}, + }, + }, {Schema: "olm.channel", Package: "foo", Name: "stable", Entries: []declcfg.ChannelEntry{ {Name: "foo.v0.2.0", Replaces: "foo.v0.1.0", SkipRange: "<0.2.0", Skips: []string{"foo.v0.1.1", "foo.v0.1.2"}}, }}, diff --git a/alpha/action/testdata/foo-index-v0.2.0-declcfg/foo/index.yaml b/alpha/action/testdata/foo-index-v0.2.0-declcfg/foo/index.yaml index 7a126ee50..933b108d2 100644 --- a/alpha/action/testdata/foo-index-v0.2.0-declcfg/foo/index.yaml +++ b/alpha/action/testdata/foo-index-v0.2.0-declcfg/foo/index.yaml @@ -2,6 +2,11 @@ schema: olm.package name: foo defaultChannel: beta +properties: + - type: owner + value: + group: abc.com + name: admin --- schema: olm.channel package: foo @@ -15,6 +20,11 @@ entries: skips: - foo.v0.1.1 - foo.v0.1.2 +properties: + - type: user + value: + group: xyz.com + name: account --- schema: olm.channel package: foo diff --git a/alpha/declcfg/declcfg.go b/alpha/declcfg/declcfg.go index 688d5982a..7579c97e3 100644 --- a/alpha/declcfg/declcfg.go +++ b/alpha/declcfg/declcfg.go @@ -20,11 +20,12 @@ type DeclarativeConfig struct { } type Package struct { - Schema string `json:"schema"` - Name string `json:"name"` - DefaultChannel string `json:"defaultChannel"` - Icon *Icon `json:"icon,omitempty"` - Description string `json:"description,omitempty"` + Schema string `json:"schema"` + Name string `json:"name"` + DefaultChannel string `json:"defaultChannel"` + Icon *Icon `json:"icon,omitempty"` + Description string `json:"description,omitempty"` + Properties []property.Property `json:"properties,omitempty" hash:"set"` } type Icon struct { @@ -33,10 +34,11 @@ type Icon struct { } type Channel struct { - Schema string `json:"schema"` - Name string `json:"name"` - Package string `json:"package"` - Entries []ChannelEntry `json:"entries"` + Schema string `json:"schema"` + Name string `json:"name"` + Package string `json:"package"` + Entries []ChannelEntry `json:"entries"` + Properties []property.Property `json:"properties,omitempty" hash:"set"` } type ChannelEntry struct { diff --git a/alpha/declcfg/declcfg_to_model_test.go b/alpha/declcfg/declcfg_to_model_test.go index 34c7bc020..b633c7cc3 100644 --- a/alpha/declcfg/declcfg_to_model_test.go +++ b/alpha/declcfg/declcfg_to_model_test.go @@ -248,6 +248,38 @@ func TestConvertToModel(t *testing.T) { Bundles: []Bundle{newTestBundle("foo", "0.1.0")}, }, }, + { + name: "Success/ValidModelWithChannelProperties", + assertion: require.NoError, + cfg: DeclarativeConfig{ + Packages: []Package{newTestPackage("foo", "alpha", svgSmallCircle)}, + Channels: []Channel{ + addChannelProperties( + newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"}), + []property.Property{ + {Type: "user", Value: json.RawMessage("{\"group\":\"xyz.com\",\"name\":\"account\"}")}, + }, + ), + }, + Bundles: []Bundle{newTestBundle("foo", "0.1.0")}, + }, + }, + { + name: "Success/ValidModelWithPackageProperties", + assertion: require.NoError, + cfg: DeclarativeConfig{ + Packages: []Package{ + addPackageProperties( + newTestPackage("foo", "alpha", svgSmallCircle), + []property.Property{ + {Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")}, + }, + ), + }, + Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})}, + Bundles: []Bundle{newTestBundle("foo", "0.1.0")}, + }, + }, } for _, s := range specs { diff --git a/alpha/declcfg/helpers_test.go b/alpha/declcfg/helpers_test.go index 86111c770..cb1a10e2e 100644 --- a/alpha/declcfg/helpers_test.go +++ b/alpha/declcfg/helpers_test.go @@ -159,6 +159,11 @@ func newTestPackage(packageName, defaultChannel, svgData string) Package { return p } +func addPackageProperties(in Package, p []property.Property) Package { + in.Properties = p + return in +} + func newTestChannel(packageName, channelName string, entries ...ChannelEntry) Channel { return Channel{ Schema: schemaChannel, @@ -168,6 +173,11 @@ func newTestChannel(packageName, channelName string, entries ...ChannelEntry) Ch } } +func addChannelProperties(in Channel, p []property.Property) Channel { + in.Properties = p + return in +} + func buildTestModel() model.Model { return model.Model{ "anakin": buildAnakinPkgModel(),