Skip to content

Commit 2fd7a7e

Browse files
committed
GreaterThan/LessThan fixed for equal values
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent 25424d4 commit 2fd7a7e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

version.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ func (v *Version) Equal(b *Version) bool {
2222

2323
// GreaterThan returns true if the version is greater than the supplied version
2424
func (v *Version) GreaterThan(b *Version) bool {
25+
if v.String() == b.String() {
26+
return false
27+
}
2528
p := pair(v, b)
2629
sort.Sort(p)
2730
return v.String() == p[1].String()
2831
}
2932

3033
// LessThan returns true if the version is lower than the supplied version
3134
func (v *Version) LessThan(b *Version) bool {
35+
if v.String() == b.String() {
36+
return false
37+
}
3238
return !v.GreaterThan(b)
3339
}
3440

version_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestK0sComparison(t *testing.T) {
3030
b, err := NewVersion("1.23.1+k0s.2")
3131
assert.NoError(t, err)
3232
assert.True(t, b.GreaterThan(a), "version %s should be greater than %s", b, a)
33+
assert.False(t, a.GreaterThan(a), "version %s should not be greater than %s", a, a)
3334
assert.True(t, a.LessThan(b), "version %s should be less than %s", b, a)
35+
assert.False(t, a.LessThan(a), "version %s should not be less than %s", a, a)
3436
assert.False(t, b.Equal(a), "version %s should not be equal to %s", b, a)
3537
}

0 commit comments

Comments
 (0)