Skip to content

Commit d663a0d

Browse files
grokspawnci-robot
authored andcommitted
Deprecation utests (#1164)
* deprecations unit tests Signed-off-by: Jordan Keister <[email protected]> * review updates Signed-off-by: Jordan Keister <[email protected]> * dogmatic review updates Signed-off-by: Jordan Keister <[email protected]> --------- Signed-off-by: Jordan Keister <[email protected]> Upstream-repository: operator-registry Upstream-commit: 39df3b78e77574c64cc05e480cbd6fe83cf2b428
1 parent 42ed2b2 commit d663a0d

File tree

5 files changed

+563
-58
lines changed

5 files changed

+563
-58
lines changed

staging/operator-registry/alpha/declcfg/declcfg_to_model_test.go

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,155 @@ func TestConvertToModel(t *testing.T) {
280280
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
281281
},
282282
},
283+
{
284+
name: "Error/Deprecation/UnspecifiedPackage",
285+
assertion: hasError(`package name must be set for deprecation item 0`),
286+
cfg: DeclarativeConfig{
287+
Packages: []Package{
288+
addPackageProperties(
289+
newTestPackage("foo", "alpha", svgSmallCircle),
290+
[]property.Property{
291+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
292+
},
293+
),
294+
},
295+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
296+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
297+
Deprecations: []Deprecation{
298+
{Schema: SchemaDeprecation},
299+
},
300+
},
301+
},
302+
{
303+
name: "Error/Deprecation/OutOfBoundsBundle",
304+
assertion: hasError(`cannot deprecate bundle "foo.v2.0.0" for package "foo": bundle not found`),
305+
cfg: DeclarativeConfig{
306+
Packages: []Package{
307+
addPackageProperties(
308+
newTestPackage("foo", "alpha", svgSmallCircle),
309+
[]property.Property{
310+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
311+
},
312+
),
313+
},
314+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
315+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
316+
Deprecations: []Deprecation{
317+
{
318+
Schema: SchemaDeprecation,
319+
Package: "foo",
320+
Entries: []DeprecationEntry{
321+
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v2.0.0"}, Message: "foo.v2.0.0 doesn't exist in the first place"},
322+
},
323+
},
324+
},
325+
},
326+
},
327+
{
328+
name: "Error/Deprecation/OutOfBoundsPackage",
329+
assertion: hasError(`cannot apply deprecations to an unknown package "nyarl"`),
330+
cfg: DeclarativeConfig{
331+
Packages: []Package{
332+
addPackageProperties(
333+
newTestPackage("foo", "alpha", svgSmallCircle),
334+
[]property.Property{
335+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
336+
},
337+
),
338+
},
339+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
340+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
341+
Deprecations: []Deprecation{
342+
{
343+
Schema: SchemaDeprecation,
344+
Package: "nyarl",
345+
},
346+
},
347+
},
348+
},
349+
{
350+
name: "Error/Deprecation/MultiplePerPackage",
351+
assertion: hasError(`expected a maximum of one deprecation per package: "foo"`),
352+
cfg: DeclarativeConfig{
353+
Packages: []Package{
354+
addPackageProperties(
355+
newTestPackage("foo", "alpha", svgSmallCircle),
356+
[]property.Property{
357+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
358+
},
359+
),
360+
},
361+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
362+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
363+
Deprecations: []Deprecation{
364+
{
365+
Schema: SchemaDeprecation,
366+
Package: "foo",
367+
Entries: []DeprecationEntry{
368+
{Reference: PackageScopedReference{Schema: SchemaChannel, Name: "alpha"}, Message: "no more alpha channel"},
369+
},
370+
},
371+
{
372+
Schema: SchemaDeprecation,
373+
Package: "foo",
374+
Entries: []DeprecationEntry{
375+
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is dead. do another thing"},
376+
},
377+
},
378+
},
379+
},
380+
},
381+
{
382+
name: "Error/Deprecation/BadRefSchema",
383+
assertion: hasError(`cannot deprecate object declcfg.PackageScopedReference{Schema:"badschema", Name:"foo.v2.0.0"} referenced by entry 0 for package "foo": object schema unknown`),
384+
cfg: DeclarativeConfig{
385+
Packages: []Package{
386+
addPackageProperties(
387+
newTestPackage("foo", "alpha", svgSmallCircle),
388+
[]property.Property{
389+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
390+
},
391+
),
392+
},
393+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
394+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
395+
Deprecations: []Deprecation{
396+
{
397+
Schema: SchemaDeprecation,
398+
Package: "foo",
399+
Entries: []DeprecationEntry{
400+
{Reference: PackageScopedReference{Schema: "badschema", Name: "foo.v2.0.0"}, Message: "foo.v2.0.0 doesn't exist in the first place"},
401+
},
402+
},
403+
},
404+
},
405+
},
406+
{
407+
name: "Error/Deprecation/DuplicateRef",
408+
assertion: hasError(`duplicate deprecation entry declcfg.PackageScopedReference{Schema:"olm.bundle", Name:"foo.v0.1.0"} for package "foo"`),
409+
cfg: DeclarativeConfig{
410+
Packages: []Package{
411+
addPackageProperties(
412+
newTestPackage("foo", "alpha", svgSmallCircle),
413+
[]property.Property{
414+
{Type: "owner", Value: json.RawMessage("{\"group\":\"abc.com\",\"name\":\"admin\"}")},
415+
},
416+
),
417+
},
418+
Channels: []Channel{newTestChannel("foo", "alpha", ChannelEntry{Name: "foo.v0.1.0"})},
419+
Bundles: []Bundle{newTestBundle("foo", "0.1.0")},
420+
Deprecations: []Deprecation{
421+
{
422+
Schema: SchemaDeprecation,
423+
Package: "foo",
424+
Entries: []DeprecationEntry{
425+
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is bad"},
426+
{Reference: PackageScopedReference{Schema: SchemaBundle, Name: "foo.v0.1.0"}, Message: "foo.v0.1.0 is bad"},
427+
},
428+
},
429+
},
430+
},
431+
},
283432
}
284433

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

293442
func TestConvertToModelRoundtrip(t *testing.T) {
294-
expected := buildValidDeclarativeConfig(true)
443+
expected := buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: false}) // TODO: turn on deprecation when we have model-->declcfg conversion
295444

296445
m, err := ConvertToModel(expected)
297446
require.NoError(t, err)

staging/operator-registry/alpha/declcfg/helpers_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@ import (
1313
"github.com/operator-framework/operator-registry/alpha/property"
1414
)
1515

16-
func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
16+
type validDeclarativeConfigSpec struct {
17+
IncludeUnrecognized bool
18+
IncludeDeprecations bool
19+
}
20+
21+
func buildValidDeclarativeConfig(spec validDeclarativeConfigSpec) DeclarativeConfig {
1722
a001 := newTestBundle("anakin", "0.0.1")
1823
a010 := newTestBundle("anakin", "0.1.0")
1924
a011 := newTestBundle("anakin", "0.1.1")
2025
b1 := newTestBundle("boba-fett", "1.0.0")
2126
b2 := newTestBundle("boba-fett", "2.0.0")
2227

2328
var others []Meta
24-
if includeUnrecognized {
29+
if spec.IncludeUnrecognized {
2530
others = []Meta{
2631
{Schema: "custom.1", Blob: json.RawMessage(`{"schema": "custom.1"}`)},
2732
{Schema: "custom.2", Blob: json.RawMessage(`{"schema": "custom.2"}`)},
@@ -38,6 +43,38 @@ func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
3843
}
3944
}
4045

46+
var deprecations []Deprecation
47+
if spec.IncludeDeprecations {
48+
deprecations = []Deprecation{
49+
{
50+
Schema: SchemaDeprecation,
51+
Package: "anakin",
52+
Entries: []DeprecationEntry{
53+
{
54+
Reference: PackageScopedReference{
55+
Schema: "olm.bundle",
56+
Name: testBundleName("anakin", "0.0.1"),
57+
},
58+
Message: "This bundle version is deprecated",
59+
},
60+
{
61+
Reference: PackageScopedReference{
62+
Schema: "olm.channel",
63+
Name: "light",
64+
},
65+
Message: "This channel is deprecated",
66+
},
67+
{
68+
Reference: PackageScopedReference{
69+
Schema: "olm.package",
70+
},
71+
Message: "This package is deprecated... there is another",
72+
},
73+
},
74+
},
75+
}
76+
}
77+
4178
return DeclarativeConfig{
4279
Packages: []Package{
4380
newTestPackage("anakin", "dark", svgSmallCircle),
@@ -81,7 +118,8 @@ func buildValidDeclarativeConfig(includeUnrecognized bool) DeclarativeConfig {
81118
a001, a010, a011,
82119
b1, b2,
83120
},
84-
Others: others,
121+
Others: others,
122+
Deprecations: deprecations,
85123
}
86124
}
87125

staging/operator-registry/alpha/declcfg/model_to_declcfg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestConvertFromModel(t *testing.T) {
1919
{
2020
name: "Success",
2121
m: buildTestModel(),
22-
expectCfg: buildValidDeclarativeConfig(false),
22+
expectCfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: false, IncludeDeprecations: false}),
2323
},
2424
}
2525

staging/operator-registry/alpha/declcfg/write_test.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestWriteJSON(t *testing.T) {
1717
specs := []spec{
1818
{
1919
name: "Success",
20-
cfg: buildValidDeclarativeConfig(true),
20+
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
2121
expected: `{
2222
"schema": "olm.package",
2323
"name": "anakin",
@@ -167,6 +167,32 @@ func TestWriteJSON(t *testing.T) {
167167
"package": "anakin",
168168
"schema": "custom.3"
169169
}
170+
{
171+
"schema": "olm.deprecations",
172+
"package": "anakin",
173+
"entries": [
174+
{
175+
"reference": {
176+
"schema": "olm.bundle",
177+
"name": "anakin.v0.0.1"
178+
},
179+
"message": "This bundle version is deprecated"
180+
},
181+
{
182+
"reference": {
183+
"schema": "olm.channel",
184+
"name": "light"
185+
},
186+
"message": "This channel is deprecated"
187+
},
188+
{
189+
"reference": {
190+
"schema": "olm.package"
191+
},
192+
"message": "This package is deprecated... there is another"
193+
}
194+
]
195+
}
170196
{
171197
"schema": "olm.package",
172198
"name": "boba-fett",
@@ -290,7 +316,7 @@ func TestWriteYAML(t *testing.T) {
290316
specs := []spec{
291317
{
292318
name: "Success",
293-
cfg: buildValidDeclarativeConfig(true),
319+
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
294320
expected: `---
295321
defaultChannel: dark
296322
description: anakin operator
@@ -381,6 +407,21 @@ myField: foobar
381407
package: anakin
382408
schema: custom.3
383409
---
410+
entries:
411+
- message: This bundle version is deprecated
412+
reference:
413+
name: anakin.v0.0.1
414+
schema: olm.bundle
415+
- message: This channel is deprecated
416+
reference:
417+
name: light
418+
schema: olm.channel
419+
- message: This package is deprecated... there is another
420+
reference:
421+
schema: olm.package
422+
package: anakin
423+
schema: olm.deprecations
424+
---
384425
defaultChannel: mando
385426
description: boba-fett operator
386427
icon:
@@ -481,7 +522,7 @@ func TestWriteMermaidChannels(t *testing.T) {
481522
specs := []spec{
482523
{
483524
name: "SuccessNoFilters",
484-
cfg: buildValidDeclarativeConfig(true),
525+
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
485526
startEdge: "",
486527
packageFilter: "",
487528
expected: `graph LR
@@ -516,7 +557,7 @@ func TestWriteMermaidChannels(t *testing.T) {
516557
},
517558
{
518559
name: "SuccessMinEdgeFilter",
519-
cfg: buildValidDeclarativeConfig(true),
560+
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
520561
startEdge: "anakin.v0.1.0",
521562
packageFilter: "",
522563
expected: `graph LR
@@ -537,7 +578,7 @@ func TestWriteMermaidChannels(t *testing.T) {
537578
},
538579
{
539580
name: "SuccessPackageNameFilter",
540-
cfg: buildValidDeclarativeConfig(true),
581+
cfg: buildValidDeclarativeConfig(validDeclarativeConfigSpec{IncludeUnrecognized: true, IncludeDeprecations: true}),
541582
startEdge: "",
542583
packageFilter: "boba-fett",
543584
expected: `graph LR

0 commit comments

Comments
 (0)