Skip to content

Deprecation utests #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 150 additions & 1 deletion alpha/declcfg/declcfg_to_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,155 @@ func TestConvertToModel(t *testing.T) {
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
},
},
{
name: "Error/Deprecation/UnspecifiedPackage",
assertion: hasError(`package name must be set for deprecation item 0`),
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")},
Deprecations: []Deprecation{
{Schema: SchemaDeprecation},
},
},
},
{
name: "Error/Deprecation/OutOfBoundsBundle",
assertion: hasError(`cannot deprecate bundle "foo.v2.0.0" for package "foo": bundle not found`),
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")},
Deprecations: []Deprecation{
{
Schema: SchemaDeprecation,
Package: "foo",
Entries: []DeprecationEntry{
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v2.0.0"}, Message: "foo.v2.0.0 doesn't exist in the first place"},
},
},
},
},
},
{
name: "Error/Deprecation/OutOfBoundsPackage",
assertion: hasError(`cannot apply deprecations to an unknown package "nyarl"`),
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")},
Deprecations: []Deprecation{
{
Schema: SchemaDeprecation,
Package: "nyarl",
},
},
},
},
{
name: "Error/Deprecation/MultiplePerPackage",
assertion: hasError(`expected a maximum of one deprecation per package: "foo"`),
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")},
Deprecations: []Deprecation{
{
Schema: SchemaDeprecation,
Package: "foo",
Entries: []DeprecationEntry{
{Reference: PackageScopedReference{Schema: SchemaChannel, Name: "alpha"}, Message: "no more alpha channel"},
},
},
{
Schema: SchemaDeprecation,
Package: "foo",
Entries: []DeprecationEntry{
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is dead. do another thing"},
},
},
},
},
},
{
name: "Error/Deprecation/BadRefSchema",
assertion: hasError(`cannot deprecate object declcfg.PackageScopedReference{Schema:"badschema", Name:"foo.v2.0.0"} referenced by entry 0 for package "foo": object schema unknown`),
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")},
Deprecations: []Deprecation{
{
Schema: SchemaDeprecation,
Package: "foo",
Entries: []DeprecationEntry{
{Reference: PackageScopedReference{Schema: "badschema", Name: "foo.v2.0.0"}, Message: "foo.v2.0.0 doesn't exist in the first place"},
},
},
},
},
},
{
name: "Error/Deprecation/DuplicateRef",
assertion: hasError(`duplicate deprecation entry declcfg.PackageScopedReference{Schema:"olm.bundle", Name:"foo.v0.1.0"} for package "foo"`),
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")},
Deprecations: []Deprecation{
{
Schema: SchemaDeprecation,
Package: "foo",
Entries: []DeprecationEntry{
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is bad"},
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is bad"},
},
},
},
},
},
}

for _, s := range specs {
Expand All @@ -291,7 +440,7 @@ func TestConvertToModel(t *testing.T) {
}

func TestConvertToModelRoundtrip(t *testing.T) {
expected := buildValidDeclarativeConfig(true)
expected := buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: false}) // TODO: turn on deprecation when we have model-->declcfg conversion
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function goes declcfg --> model --> declcfg and compares the start and finish products. We don't yet have backwards conversion, so this can't be enabled until #1162 lands.


m, err := ConvertToModel(expected)
require.NoError(t, err)
Expand Down
44 changes: 41 additions & 3 deletions alpha/declcfg/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ import (
"github.com/operator-framework/operator-registry/alpha/property"
)

func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
type validDeclarativeConfigSpec struct {
IncludeUnrecognized bool
IncludeDeprecations bool
}

func buildValidDeclarativeConfig(spec validDeclarativeConfigSpec) DeclarativeConfig {
a001 := newTestBundle("anakin", "0.0.1")
a010 := newTestBundle("anakin", "0.1.0")
a011 := newTestBundle("anakin", "0.1.1")
b1 := newTestBundle("boba-fett", "1.0.0")
b2 := newTestBundle("boba-fett", "2.0.0")

var others []Meta
if includeUnrecognized {
if spec.IncludeUnrecognized {
others = []Meta{
{Schema: "custom.1", Blob: json.RawMessage(`{"schema": "custom.1"}`)},
{Schema: "custom.2", Blob: json.RawMessage(`{"schema": "custom.2"}`)},
Expand All @@ -38,6 +43,38 @@ func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
}
}

var deprecations []Deprecation
if spec.IncludeDeprecations {
deprecations = []Deprecation{
{
Schema: SchemaDeprecation,
Package: "anakin",
Entries: []DeprecationEntry{
{
Reference: PackageScopedReference{
Schema: "olm.bundle",
Name: testBundleName("anakin", "0.0.1"),
},
Message: "This bundle version is deprecated",
},
{
Reference: PackageScopedReference{
Schema: "olm.channel",
Name: "light",
},
Message: "This channel is deprecated",
},
{
Reference: PackageScopedReference{
Schema: "olm.package",
},
Message: "This package is deprecated... there is another",
},
},
},
}
}

return DeclarativeConfig{
Packages: []Package{
newTestPackage("anakin", "dark", svgSmallCircle),
Expand Down Expand Up @@ -81,7 +118,8 @@ func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
a001, a010, a011,
b1, b2,
},
Others: others,
Others: others,
Deprecations: deprecations,
}
}

Expand Down
2 changes: 1 addition & 1 deletion alpha/declcfg/model_to_declcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestConvertFromModel(t *testing.T) {
{
name: "Success",
m: buildTestModel(),
expectCfg: buildValidDeclarativeConfig(false),
expectCfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: false, IncludeDeprecations: false}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1162 will make this false, true

},
}

Expand Down
51 changes: 46 additions & 5 deletions alpha/declcfg/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestWriteJSON(t *testing.T) {
specs := []spec{
{
name: "Success",
cfg: buildValidDeclarativeConfig(true),
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
expected: `{
"schema": "olm.package",
"name": "anakin",
Expand Down Expand Up @@ -167,6 +167,32 @@ func TestWriteJSON(t *testing.T) {
"package": "anakin",
"schema": "custom.3"
}
{
"schema": "olm.deprecations",
"package": "anakin",
"entries": [
{
"reference": {
"schema": "olm.bundle",
"name": "anakin.v0.0.1"
},
"message": "This bundle version is deprecated"
},
{
"reference": {
"schema": "olm.channel",
"name": "light"
},
"message": "This channel is deprecated"
},
{
"reference": {
"schema": "olm.package"
},
"message": "This package is deprecated... there is another"
}
]
}
{
"schema": "olm.package",
"name": "boba-fett",
Expand Down Expand Up @@ -290,7 +316,7 @@ func TestWriteYAML(t *testing.T) {
specs := []spec{
{
name: "Success",
cfg: buildValidDeclarativeConfig(true),
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
expected: `---
defaultChannel: dark
description: anakin operator
Expand Down Expand Up @@ -381,6 +407,21 @@ myField: foobar
package: anakin
schema: custom.3
---
entries:
- message: This bundle version is deprecated
reference:
name: anakin.v0.0.1
schema: olm.bundle
- message: This channel is deprecated
reference:
name: light
schema: olm.channel
- message: This package is deprecated... there is another
reference:
schema: olm.package
package: anakin
schema: olm.deprecations
---
defaultChannel: mando
description: boba-fett operator
icon:
Expand Down Expand Up @@ -481,7 +522,7 @@ func TestWriteMermaidChannels(t *testing.T) {
specs := []spec{
{
name: "SuccessNoFilters",
cfg: buildValidDeclarativeConfig(true),
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
startEdge: "",
packageFilter: "",
expected: `graph LR
Expand Down Expand Up @@ -516,7 +557,7 @@ func TestWriteMermaidChannels(t *testing.T) {
},
{
name: "SuccessMinEdgeFilter",
cfg: buildValidDeclarativeConfig(true),
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
startEdge: "anakin.v0.1.0",
packageFilter: "",
expected: `graph LR
Expand All @@ -537,7 +578,7 @@ func TestWriteMermaidChannels(t *testing.T) {
},
{
name: "SuccessPackageNameFilter",
cfg: buildValidDeclarativeConfig(true),
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
startEdge: "",
packageFilter: "boba-fett",
expected: `graph LR
Expand Down
Loading