@@ -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
293442func 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 )
0 commit comments