Skip to content

Commit 826b46f

Browse files
Merge pull request #647 from sudhanvaghebbale/shebbale/bug-6150-semver-version-compare
Fix version semver comparison when equal #6150
2 parents 45a7688 + 1605b09 commit 826b46f

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

update/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func IsOutdated(current, latest string) bool {
8282
// fallback to naive comparison
8383
return current != latest
8484
}
85-
return latestVer.GreaterThan(currentVer)
85+
return currentVer.LessThan(latestVer)
8686
}
8787

8888
// IsDevReleaseOutdated returns true if installed tool (dev version) is outdated

update/types_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package updateutils
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestIsOutdated(t *testing.T) {
11+
tests := []struct {
12+
current string
13+
latest string
14+
expected bool
15+
}{
16+
{
17+
current: "1.0.0",
18+
latest: "1.1.0",
19+
expected: true,
20+
},
21+
{
22+
current: "1.0.0",
23+
latest: "1.0.0",
24+
expected: false,
25+
},
26+
{
27+
current: "1.1.0",
28+
latest: "1.0.0",
29+
expected: false,
30+
},
31+
{
32+
current: "1.0.0-dev",
33+
latest: "1.0.0",
34+
expected: true,
35+
},
36+
{
37+
current: "invalid",
38+
latest: "1.0.0",
39+
expected: true,
40+
},
41+
{
42+
current: "invalid1",
43+
latest: "invalid2",
44+
expected: true,
45+
},
46+
{
47+
current: "1.0.0-alpha",
48+
latest: "1.0.0",
49+
expected: true,
50+
},
51+
{
52+
current: "1.0.0-alpha",
53+
latest: "1.0.0-beta",
54+
expected: true,
55+
},
56+
}
57+
58+
for _, tt := range tests {
59+
t.Run(fmt.Sprintf("current: %v, latest: %v", tt.current, tt.latest), func(t *testing.T) {
60+
assert.Equal(t, tt.expected, IsOutdated(tt.current, tt.latest), "version comparison failed")
61+
})
62+
}
63+
}

0 commit comments

Comments
 (0)