@@ -73,44 +73,76 @@ func TestInAnyChannel(t *testing.T) {
7373func TestSameVersionHigherRelease (t * testing.T ) {
7474 const testPackageName = "test-package"
7575
76- // Expected bundle version 2.0.0+1
77- expect , err := bundle .NewLegacyRegistryV1VersionRelease ("2.0.0+1" )
78- require .NoError (t , err )
79-
8076 tests := []struct {
8177 name string
78+ expectVersion string
8279 bundleVersion string
8380 shouldMatch bool
8481 }{
82+ // Starting from a version with release
8583 {
86- name : "same version, higher release" ,
84+ name : "from version with release - higher release matches" ,
85+ expectVersion : "2.0.0+1" ,
8786 bundleVersion : "2.0.0+2" ,
8887 shouldMatch : true ,
8988 },
9089 {
91- name : "same version, same release" ,
90+ name : "from version with release - same release does not match" ,
91+ expectVersion : "2.0.0+1" ,
9292 bundleVersion : "2.0.0+1" ,
9393 shouldMatch : false ,
9494 },
9595 {
96- name : "same version, lower release" ,
96+ name : "from version with release - lower release does not match" ,
97+ expectVersion : "2.0.0+1" ,
9798 bundleVersion : "2.0.0+0" ,
9899 shouldMatch : false ,
99100 },
100101 {
101- name : "same version, no release" ,
102+ name : "from version with release - different version does not match" ,
103+ expectVersion : "2.0.0+1" ,
104+ bundleVersion : "2.1.0+2" ,
105+ shouldMatch : false ,
106+ },
107+ // Starting from a version without release
108+ {
109+ name : "from version without release - bundle with release matches" ,
110+ expectVersion : "2.0.0" ,
111+ bundleVersion : "2.0.0+1" ,
112+ shouldMatch : true ,
113+ },
114+ {
115+ name : "from version without release - bundle without release does not match" ,
116+ expectVersion : "2.0.0" ,
102117 bundleVersion : "2.0.0" ,
103118 shouldMatch : false ,
104119 },
105120 {
106- name : "different version, higher release" ,
107- bundleVersion : "2.1.0+2" ,
121+ name : "from version without release - different version does not match" ,
122+ expectVersion : "2.0.0" ,
123+ bundleVersion : "2.1.0+1" ,
108124 shouldMatch : false ,
109125 },
126+ // Starting from different base versions
127+ {
128+ name : "from 1.0.0+5 - higher release matches" ,
129+ expectVersion : "1.0.0+5" ,
130+ bundleVersion : "1.0.0+10" ,
131+ shouldMatch : true ,
132+ },
133+ {
134+ name : "from 3.5.2+1 - higher release matches" ,
135+ expectVersion : "3.5.2+1" ,
136+ bundleVersion : "3.5.2+2" ,
137+ shouldMatch : true ,
138+ },
110139 }
111140
112141 for _ , tt := range tests {
113142 t .Run (tt .name , func (t * testing.T ) {
143+ expect , err := bundle .NewLegacyRegistryV1VersionRelease (tt .expectVersion )
144+ require .NoError (t , err )
145+
114146 testBundle := declcfg.Bundle {
115147 Name : "test-package.v" + tt .bundleVersion ,
116148 Package : testPackageName ,
@@ -120,30 +152,15 @@ func TestSameVersionHigherRelease(t *testing.T) {
120152 }
121153
122154 f := filter .SameVersionHigherRelease (* expect )
123- assert .Equal (t , tt .shouldMatch , f (testBundle ), "version %s should match=%v " , tt .bundleVersion , tt .shouldMatch )
155+ assert .Equal (t , tt .shouldMatch , f (testBundle ), "comparing %s to %s " , tt .bundleVersion , tt .expectVersion )
124156 })
125157 }
126158
127- // Test when expected version has no release (e.g: "2.0.0")
128- t .Run ("expected version without release" , func (t * testing.T ) {
129- expectNoRelease , err := bundle .NewLegacyRegistryV1VersionRelease ("2.0.0" )
130- require .NoError (t , err )
131-
132- // Bundle with release should be considered higher
133- bundleWithRelease := declcfg.Bundle {
134- Name : "test-package.v2.0.0+1" ,
135- Package : testPackageName ,
136- Properties : []property.Property {
137- property .MustBuildPackage (testPackageName , "2.0.0+1" ),
138- },
139- }
140-
141- f := filter .SameVersionHigherRelease (* expectNoRelease )
142- assert .True (t , f (bundleWithRelease ), "2.0.0+1 should be higher than 2.0.0" )
143- })
144-
145159 // Test error case: invalid bundle (no package property)
146160 t .Run ("invalid bundle - no package property" , func (t * testing.T ) {
161+ expect , err := bundle .NewLegacyRegistryV1VersionRelease ("2.0.0+1" )
162+ require .NoError (t , err )
163+
147164 testBundle := declcfg.Bundle {
148165 Name : "test-package.invalid" ,
149166 Package : testPackageName ,
@@ -156,7 +173,7 @@ func TestSameVersionHigherRelease(t *testing.T) {
156173
157174 // Test with explicit pkg.Release field (new bundle format)
158175 t .Run ("explicit release field - higher release matches" , func (t * testing.T ) {
159- expectExplicit , err := bundle .NewLegacyRegistryV1VersionRelease ("2.0.0+1" )
176+ expect , err := bundle .NewLegacyRegistryV1VersionRelease ("2.0.0+1" )
160177 require .NoError (t , err )
161178
162179 bundleWithExplicitRelease := declcfg.Bundle {
@@ -167,7 +184,7 @@ func TestSameVersionHigherRelease(t *testing.T) {
167184 },
168185 }
169186
170- f := filter .SameVersionHigherRelease (* expectExplicit )
187+ f := filter .SameVersionHigherRelease (* expect )
171188 assert .True (t , f (bundleWithExplicitRelease ), "explicit release=2 should be higher than 2.0.0+1" )
172189 })
173190}
0 commit comments