@@ -4,9 +4,11 @@ import (
4
4
"encoding/json"
5
5
"testing"
6
6
7
+ "github.com/blang/semver/v4"
7
8
"github.com/stretchr/testify/assert"
8
9
"github.com/stretchr/testify/require"
9
10
11
+ "github.com/operator-framework/operator-registry/alpha/model"
10
12
"github.com/operator-framework/operator-registry/alpha/property"
11
13
)
12
14
@@ -450,6 +452,41 @@ func TestConvertToModel(t *testing.T) {
450
452
}
451
453
}
452
454
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
+
453
490
func TestConvertToModelRoundtrip (t * testing.T ) {
454
491
expected := buildValidDeclarativeConfig (validDeclarativeConfigSpec {IncludeUnrecognized : true , IncludeDeprecations : false }) // TODO: turn on deprecation when we have model-->declcfg conversion
455
492
0 commit comments