Skip to content

Commit a66d732

Browse files
fix up tests
Signed-off-by: Rashmi Gottipati <rgottipa@redhat.com>
1 parent 116b8e1 commit a66d732

2 files changed

Lines changed: 21 additions & 40 deletions

File tree

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

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ func TestByVersionAndRelease(t *testing.T) {
140140
t.Run("all bundles valid", func(t *testing.T) {
141141
toSort := []declcfg.Bundle{b3_1, b2, b3_2, b1}
142142
slices.SortStableFunc(toSort, compare.ByVersionAndRelease)
143-
assert.Equal(t, []declcfg.Bundle{b1, b3_2, b3_1, b2}, toSort)
143+
assert.Equal(t, []declcfg.Bundle{b1, b3_2, b3_1, b2}, toSort, "should sort descending: 1.0.0 > 1.0.0-alpha+2 > 1.0.0-alpha+1 > 0.0.1")
144144
})
145145

146146
t.Run("some bundles are missing version", func(t *testing.T) {
147147
toSort := []declcfg.Bundle{b3_1, b4noVersion, b2, b3_2, b5empty, b1}
148148
slices.SortStableFunc(toSort, compare.ByVersionAndRelease)
149-
assert.Equal(t, []declcfg.Bundle{b1, b3_2, b3_1, b2, b4noVersion, b5empty}, toSort)
149+
assert.Equal(t, []declcfg.Bundle{b1, b3_2, b3_1, b2, b4noVersion, b5empty}, toSort, "bundles with invalid/missing versions should sort last")
150150
})
151151
}
152152

@@ -163,66 +163,47 @@ func TestByDeprecationFunc(t *testing.T) {
163163
c := declcfg.Bundle{Name: "c"}
164164
d := declcfg.Bundle{Name: "d"}
165165

166-
assert.Equal(t, 0, byDeprecation(a, b))
167-
assert.Equal(t, 0, byDeprecation(b, a))
168-
assert.Equal(t, 1, byDeprecation(a, c))
169-
assert.Equal(t, -1, byDeprecation(c, a))
170-
assert.Equal(t, 0, byDeprecation(c, d))
171-
assert.Equal(t, 0, byDeprecation(d, c))
166+
assert.Equal(t, 0, byDeprecation(a, b), "both deprecated bundles are equal")
167+
assert.Equal(t, 0, byDeprecation(b, a), "both deprecated bundles are equal")
168+
assert.Equal(t, 1, byDeprecation(a, c), "deprecated bundle 'a' should sort after non-deprecated 'c'")
169+
assert.Equal(t, -1, byDeprecation(c, a), "non-deprecated bundle 'c' should sort before deprecated 'a'")
170+
assert.Equal(t, 0, byDeprecation(c, d), "both non-deprecated bundles are equal")
171+
assert.Equal(t, 0, byDeprecation(d, c), "both non-deprecated bundles are equal")
172172
}
173173

174-
// TestByVersionAndRelease_WithCompositeVersionComparison tests the feature-gated hybrid comparison:
175-
// When disabled: uses build metadata (backward compatible)
176-
// When enabled: uses Bundle.Compare() with build metadata fallback for registry+v1
174+
// TestByVersionAndRelease_WithCompositeVersionComparison tests the feature-gated hybrid comparison
175+
// for registry+v1 bundles. When the feature gate is enabled, Bundle.Compare() is called but returns
176+
// 0 for registry+v1 bundles (no explicit release field), so we fall back to build metadata parsing.
177+
// This maintains backward compatibility while preparing for future bundle formats with explicit release.
177178
func TestByVersionAndRelease_WithCompositeVersionComparison(t *testing.T) {
178179
// Registry+v1 bundles: same version, different build metadata
179-
registryV1_b1 := declcfg.Bundle{
180+
b1 := declcfg.Bundle{
180181
Name: "package1.v1.0.0+1",
181182
Properties: []property.Property{
182183
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "package1", "version": "1.0.0+1"}`)},
183184
},
184185
}
185-
registryV1_b2 := declcfg.Bundle{
186+
b2 := declcfg.Bundle{
186187
Name: "package1.v1.0.0+2",
187188
Properties: []property.Property{
188189
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "package1", "version": "1.0.0+2"}`)},
189190
},
190191
}
191192

192-
// New format bundles: same version, different .spec.release
193-
newFormat_b1 := declcfg.Bundle{
194-
Name: "package2.v1.0.0-rel.1",
195-
Properties: []property.Property{
196-
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "package2", "version": "1.0.0", "release": "1"}`)},
197-
},
198-
}
199-
newFormat_b2 := declcfg.Bundle{
200-
Name: "package2.v1.0.0-rel.2",
201-
Properties: []property.Property{
202-
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "package2", "version": "1.0.0", "release": "2"}`)},
203-
},
204-
}
205-
206193
prevEnabled := features.OperatorControllerFeatureGate.Enabled(features.CompositeVersionComparison)
207194
t.Cleanup(func() {
208195
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("%s=%t", features.CompositeVersionComparison, prevEnabled)))
209196
})
210197

211-
t.Run("feature gate disabled - uses build metadata", func(t *testing.T) {
198+
t.Run("feature gate disabled - uses build metadata only", func(t *testing.T) {
212199
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("%s=false", features.CompositeVersionComparison)))
213-
result := compare.ByVersionAndRelease(registryV1_b1, registryV1_b2)
200+
result := compare.ByVersionAndRelease(b1, b2)
214201
assert.Positive(t, result, "should sort by build metadata: 1.0.0+2 > 1.0.0+1")
215202
})
216203

217-
t.Run("feature gate enabled - registry+v1 bundles use build metadata fallback", func(t *testing.T) {
218-
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("%s=true", features.CompositeVersionComparison)))
219-
result := compare.ByVersionAndRelease(registryV1_b1, registryV1_b2)
220-
assert.Positive(t, result, "should fallback to build metadata: 1.0.0+2 > 1.0.0+1")
221-
})
222-
223-
t.Run("feature gate enabled - new format bundles use .spec.release", func(t *testing.T) {
204+
t.Run("feature gate enabled - registry+v1 bundles still work via build metadata fallback", func(t *testing.T) {
224205
require.NoError(t, features.OperatorControllerFeatureGate.Set(fmt.Sprintf("%s=true", features.CompositeVersionComparison)))
225-
result := compare.ByVersionAndRelease(newFormat_b1, newFormat_b2)
226-
assert.Positive(t, result, "should use .spec.release: release=2 > release=1")
206+
result := compare.ByVersionAndRelease(b1, b2)
207+
assert.Positive(t, result, "Bundle.Compare() returns 0, fallback to build metadata: 1.0.0+2 > 1.0.0+1")
227208
})
228209
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func TestSuccessorsOf_WithCompositeVersionComparison_FeatureGateDisabled(t *test
279279
require.NoError(t, err)
280280

281281
// Higher release should NOT match without feature gate
282-
assert.False(t, predicate(higherRelease))
282+
assert.False(t, predicate(higherRelease), "1.0.0+2 should NOT be a successor of 1.0.0+1 when feature gate disabled")
283283
}
284284

285285
// TestSuccessorsOf_WithCompositeVersionComparison_FeatureGateEnabled verifies higher releases
@@ -318,5 +318,5 @@ func TestSuccessorsOf_WithCompositeVersionComparison_FeatureGateEnabled(t *testi
318318
require.NoError(t, err)
319319

320320
// Higher release should match when feature gate is enabled
321-
assert.True(t, predicate(higherRelease))
321+
assert.True(t, predicate(higherRelease), "1.0.0+2 should be a successor of 1.0.0+1 when feature gate enabled")
322322
}

0 commit comments

Comments
 (0)