@@ -2,6 +2,7 @@ package compare_test
22
33import (
44 "encoding/json"
5+ "fmt"
56 "slices"
67 "testing"
78
@@ -171,27 +172,30 @@ func TestByDeprecationFunc(t *testing.T) {
171172}
172173
173174// TestByVersionAndRelease_WithBundleReleaseSupport tests the feature-gated hybrid comparison.
174- // This test detects the current feature gate state and validates the correct behavior path.
175- // When BundleReleaseSupport is enabled (experimental release), it uses Bundle.Compare()
176- // with build metadata fallback. When disabled (standard release), it uses legacy build metadata only.
175+ // Explicitly sets the gate to test both enabled and disabled paths.
177176func TestByVersionAndRelease_WithBundleReleaseSupport (t * testing.T ) {
178- // Registry+v1 bundles: same version, different build metadata
179- b1 := declcfg.Bundle {
180- Name : "package1.v1.0.0+1" ,
181- Properties : []property.Property {
182- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+1"}` )},
183- },
184- }
185- b2 := declcfg.Bundle {
186- Name : "package1.v1.0.0+2" ,
187- Properties : []property.Property {
188- {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+2"}` )},
189- },
190- }
177+ t .Run ("gate enabled - uses Bundle.Compare with build metadata fallback" , func (t * testing.T ) {
178+ // Enable the feature gate for this test
179+ prevEnabled := features .OperatorControllerFeatureGate .Enabled (features .BundleReleaseSupport )
180+ require .NoError (t , features .OperatorControllerFeatureGate .Set ("BundleReleaseSupport=true" ))
181+ t .Cleanup (func () {
182+ require .NoError (t , features .OperatorControllerFeatureGate .Set (fmt .Sprintf ("BundleReleaseSupport=%t" , prevEnabled )))
183+ })
184+
185+ // Registry+v1 bundles: same version, different build metadata
186+ b1 := declcfg.Bundle {
187+ Name : "package1.v1.0.0+1" ,
188+ Properties : []property.Property {
189+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+1"}` )},
190+ },
191+ }
192+ b2 := declcfg.Bundle {
193+ Name : "package1.v1.0.0+2" ,
194+ Properties : []property.Property {
195+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+2"}` )},
196+ },
197+ }
191198
192- // Detect current feature gate state and test the appropriate path
193- if features .OperatorControllerFeatureGate .Enabled (features .BundleReleaseSupport ) {
194- t .Log ("BundleReleaseSupport enabled - testing hybrid comparison with build metadata fallback" )
195199 result := compare .ByVersionAndRelease (b1 , b2 )
196200 assert .Positive (t , result , "Bundle.Compare() returns 0 for registry+v1, fallback to build metadata: 1.0.0+2 > 1.0.0+1" )
197201
@@ -210,9 +214,31 @@ func TestByVersionAndRelease_WithBundleReleaseSupport(t *testing.T) {
210214 }
211215 result = compare .ByVersionAndRelease (explicitR1 , explicitR2 )
212216 assert .Positive (t , result , "2.0.0+release.2 > 2.0.0+release.1 (explicit release field)" )
213- } else {
214- t .Log ("BundleReleaseSupport disabled - testing legacy build metadata comparison only" )
217+ })
218+
219+ t .Run ("gate disabled - uses legacy build metadata comparison only" , func (t * testing.T ) {
220+ // Disable the feature gate for this test
221+ prevEnabled := features .OperatorControllerFeatureGate .Enabled (features .BundleReleaseSupport )
222+ require .NoError (t , features .OperatorControllerFeatureGate .Set ("BundleReleaseSupport=false" ))
223+ t .Cleanup (func () {
224+ require .NoError (t , features .OperatorControllerFeatureGate .Set (fmt .Sprintf ("BundleReleaseSupport=%t" , prevEnabled )))
225+ })
226+
227+ // Registry+v1 bundles: same version, different build metadata
228+ b1 := declcfg.Bundle {
229+ Name : "package1.v1.0.0+1" ,
230+ Properties : []property.Property {
231+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+1"}` )},
232+ },
233+ }
234+ b2 := declcfg.Bundle {
235+ Name : "package1.v1.0.0+2" ,
236+ Properties : []property.Property {
237+ {Type : property .TypePackage , Value : json .RawMessage (`{"packageName": "package1", "version": "1.0.0+2"}` )},
238+ },
239+ }
240+
215241 result := compare .ByVersionAndRelease (b1 , b2 )
216242 assert .Positive (t , result , "should sort by build metadata: 1.0.0+2 > 1.0.0+1" )
217- }
243+ })
218244}
0 commit comments