Skip to content

Commit 0788808

Browse files
fix codecov patch by explicitly setting feature gate in tests
Signed-off-by: Rashmi Gottipati <rgottipa@redhat.com>
1 parent 7931651 commit 0788808

4 files changed

Lines changed: 99 additions & 48 deletions

File tree

internal/operator-controller/bundleutil/bundle_test.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bundleutil_test
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"testing"
67

78
bsemver "github.com/blang/semver/v4"
@@ -96,14 +97,15 @@ func TestGetVersionAndRelease(t *testing.T) {
9697
}
9798

9899
// TestGetVersionAndRelease_WithBundleReleaseSupport tests the feature-gated parsing behavior.
99-
// This test detects the current feature gate state and validates the correct behavior path.
100-
// When BundleReleaseSupport is enabled (experimental release), bundles with explicit
101-
// pkg.Release field use that value. When disabled (standard release), explicit release is
102-
// ignored and parsing falls back to legacy build metadata.
100+
// Explicitly sets the gate to test both enabled and disabled paths.
103101
func TestGetVersionAndRelease_WithBundleReleaseSupport(t *testing.T) {
104-
// Detect current feature gate state and test the appropriate path
105-
if features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport) {
106-
t.Log("BundleReleaseSupport enabled - testing explicit release field parsing")
102+
t.Run("gate enabled - parses explicit release field", func(t *testing.T) {
103+
// Enable the feature gate for this test
104+
prevEnabled := features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport)
105+
require.NoError(t, features.OperatorControllerFeatureGate.Set("BundleReleaseSupport=true"))
106+
t.Cleanup(func() {
107+
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("BundleReleaseSupport=%t", prevEnabled)))
108+
})
107109

108110
tests := []struct {
109111
name string
@@ -167,8 +169,15 @@ func TestGetVersionAndRelease_WithBundleReleaseSupport(t *testing.T) {
167169
}
168170
})
169171
}
170-
} else {
171-
t.Log("BundleReleaseSupport disabled - explicit release field ignored, falls back to build metadata")
172+
})
173+
174+
t.Run("gate disabled - ignores explicit release field, uses build metadata", func(t *testing.T) {
175+
// Disable the feature gate for this test
176+
prevEnabled := features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport)
177+
require.NoError(t, features.OperatorControllerFeatureGate.Set("BundleReleaseSupport=false"))
178+
t.Cleanup(func() {
179+
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("BundleReleaseSupport=%t", prevEnabled)))
180+
})
172181

173182
// When gate disabled, explicit release field is ignored and parsing falls back to legacy behavior
174183
bundleWithExplicitRelease := declcfg.Bundle{
@@ -192,5 +201,5 @@ func TestGetVersionAndRelease_WithBundleReleaseSupport(t *testing.T) {
192201
}),
193202
}
194203
require.Equal(t, expected, actual)
195-
}
204+
})
196205
}

internal/operator-controller/catalogmetadata/compare/compare_test.go

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package compare_test
22

33
import (
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.
177176
func 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
}

internal/operator-controller/catalogmetadata/filter/bundle_predicates_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package filter_test
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -172,11 +173,14 @@ func TestSameVersionHigherRelease(t *testing.T) {
172173
assert.False(t, f(testBundle))
173174
})
174175

175-
// Test with explicit pkg.Release field (new bundle format) - only when feature gate enabled
176+
// Test with explicit pkg.Release field (new bundle format)
176177
t.Run("explicit release field - higher release matches", func(t *testing.T) {
177-
if !features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport) {
178-
t.Skip("BundleReleaseSupport disabled - explicit release field not parsed")
179-
}
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+
})
180184

181185
expect, err := bundle.NewLegacyRegistryV1VersionRelease("2.0.0+1")
182186
require.NoError(t, err)

internal/operator-controller/catalogmetadata/filter/successors_test.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package filter
22

33
import (
4+
"fmt"
45
"slices"
56
"testing"
67

@@ -243,10 +244,7 @@ func TestLegacySuccessor(t *testing.T) {
243244
}
244245

245246
// TestSuccessorsOf_WithBundleReleaseSupport tests the feature-gated successor filtering.
246-
// This test detects the current feature gate state and validates the correct behavior path.
247-
// When BundleReleaseSupport is enabled (experimental release), bundles with the same
248-
// version but higher release are considered valid successors. When disabled (standard deployments),
249-
// only explicit channel successors (replaces/skips) are recognized.
247+
// Explicitly sets the gate to test both enabled and disabled paths.
250248
func TestSuccessorsOf_WithBundleReleaseSupport(t *testing.T) {
251249
channel := declcfg.Channel{
252250
Entries: []declcfg.ChannelEntry{
@@ -270,15 +268,29 @@ func TestSuccessorsOf_WithBundleReleaseSupport(t *testing.T) {
270268
},
271269
}
272270

273-
predicate, err := SuccessorsOf(installedBundle, channel)
274-
require.NoError(t, err)
271+
t.Run("gate enabled - same-version higher-release bundles are valid successors", func(t *testing.T) {
272+
// Enable the feature gate for this test
273+
prevEnabled := features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport)
274+
require.NoError(t, features.OperatorControllerFeatureGate.Set("BundleReleaseSupport=true"))
275+
t.Cleanup(func() {
276+
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("BundleReleaseSupport=%t", prevEnabled)))
277+
})
275278

276-
// Detect current feature gate state and test the appropriate behavior
277-
if features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport) {
278-
t.Log("BundleReleaseSupport enabled - same-version higher-release bundles are valid successors")
279+
predicate, err := SuccessorsOf(installedBundle, channel)
280+
require.NoError(t, err)
279281
assert.True(t, predicate(higherRelease), "1.0.0+2 should be a successor of 1.0.0+1 when feature gate enabled")
280-
} else {
281-
t.Log("BundleReleaseSupport disabled - only explicit channel successors recognized")
282+
})
283+
284+
t.Run("gate disabled - only explicit channel successors recognized", func(t *testing.T) {
285+
// Disable the feature gate for this test
286+
prevEnabled := features.OperatorControllerFeatureGate.Enabled(features.BundleReleaseSupport)
287+
require.NoError(t, features.OperatorControllerFeatureGate.Set("BundleReleaseSupport=false"))
288+
t.Cleanup(func() {
289+
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("BundleReleaseSupport=%t", prevEnabled)))
290+
})
291+
292+
predicate, err := SuccessorsOf(installedBundle, channel)
293+
require.NoError(t, err)
282294
assert.False(t, predicate(higherRelease), "1.0.0+2 should NOT be a successor of 1.0.0+1 when feature gate disabled")
283-
}
295+
})
284296
}

0 commit comments

Comments
 (0)