@@ -4,9 +4,11 @@ import (
44 "encoding/json"
55 "testing"
66
7+ "github.com/blang/semver/v4"
78 "github.com/stretchr/testify/assert"
89 "github.com/stretchr/testify/require"
910
11+ "github.com/operator-framework/operator-registry/alpha/model"
1012 "github.com/operator-framework/operator-registry/alpha/property"
1113)
1214
@@ -450,6 +452,41 @@ func TestConvertToModel(t *testing.T) {
450452 }
451453}
452454
455+ func TestConvertToModelBundle (t * testing.T ) {
456+ cfg := DeclarativeConfig {
457+ Packages : []Package {newTestPackage ("foo" , "alpha" , svgSmallCircle )},
458+ Channels : []Channel {newTestChannel ("foo" , "alpha" , ChannelEntry {Name : "foo.v0.1.0" })},
459+ Bundles : []Bundle {newTestBundle ("foo" , "0.1.0" )},
460+ }
461+ m , err := ConvertToModel (cfg )
462+ require .NoError (t , err )
463+
464+ pkg , ok := m ["foo" ]
465+ require .True (t , ok , "expected package 'foo' to be present" )
466+ ch , ok := pkg .Channels ["alpha" ]
467+ require .True (t , ok , "expected channel 'alpha' to be present" )
468+ b , ok := ch .Bundles ["foo.v0.1.0" ]
469+ require .True (t , ok , "expected bundle 'foo.v0.1.0' to be present" )
470+
471+ assert .Equal (t , pkg , b .Package )
472+ assert .Equal (t , ch , b .Channel )
473+ assert .Equal (t , "foo.v0.1.0" , b .Name )
474+ assert .Equal (t , "foo-bundle:v0.1.0" , b .Image )
475+ assert .Equal (t , "" , b .Replaces )
476+ assert .Nil (t , b .Skips )
477+ assert .Equal (t , "" , b .SkipRange )
478+ assert .Len (t , b .Properties , 3 )
479+ assert .Equal (t , []model.RelatedImage {{Name : "bundle" , Image : "foo-bundle:v0.1.0" }}, b .RelatedImages )
480+ assert .Nil (t , b .Deprecation )
481+ assert .Len (t , b .Objects , 2 )
482+ assert .NotEmpty (t , b .CsvJSON )
483+ assert .NotNil (t , b .PropertiesP )
484+ assert .Len (t , b .PropertiesP .BundleObjects , 2 )
485+ assert .Len (t , b .PropertiesP .Packages , 1 )
486+ assert .Equal (t , semver .MustParse ("0.1.0" ), b .Version )
487+
488+ }
489+
453490func TestConvertToModelRoundtrip (t * testing.T ) {
454491 expected := buildValidDeclarativeConfig (validDeclarativeConfigSpec {IncludeUnrecognized : true , IncludeDeprecations : false }) // TODO: turn on deprecation when we have model-->declcfg conversion
455492
0 commit comments