Skip to content

Commit 477accb

Browse files
refactor tests
Signed-off-by: Rashmi Gottipati <rgottipa@redhat.com>
1 parent 85c337b commit 477accb

2 files changed

Lines changed: 56 additions & 39 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ func TestByVersionAndRelease(t *testing.T) {
139139
t.Run("all bundles valid", func(t *testing.T) {
140140
toSort := []declcfg.Bundle{b3_1, b2, b3_2, b1}
141141
slices.SortStableFunc(toSort, compare.ByVersionAndRelease)
142-
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")
142+
assert.Equal(t, []declcfg.Bundle{b1, b3_2, b3_1, b2}, toSort)
143143
})
144144

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

@@ -162,12 +162,12 @@ func TestByDeprecationFunc(t *testing.T) {
162162
c := declcfg.Bundle{Name: "c"}
163163
d := declcfg.Bundle{Name: "d"}
164164

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

173173
// TestByVersionAndRelease_WithCompositeVersionComparison tests the feature-gated hybrid comparison.

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

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,44 +73,76 @@ func TestInAnyChannel(t *testing.T) {
7373
func 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

Comments
 (0)