|
|
@ -6,29 +6,6 @@ import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestCompareVersions(t *testing.T) {
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
|
|
|
|
ver1 string
|
|
|
|
|
|
|
|
ver2 string
|
|
|
|
|
|
|
|
out int
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{"1", "1.0.1", -1},
|
|
|
|
|
|
|
|
{"1.0.1", "1.0.2", -1},
|
|
|
|
|
|
|
|
{"1.0.3", "1.1", -1},
|
|
|
|
|
|
|
|
{"1.1", "1.1.1", -1},
|
|
|
|
|
|
|
|
{"1.3.2", "1.2", 1},
|
|
|
|
|
|
|
|
{"1.1.1", "1.1.1", 0},
|
|
|
|
|
|
|
|
{"1.1.0", "1.1", 0},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, each := range cases {
|
|
|
|
|
|
|
|
t.Run(each.ver1, func(t *testing.T) {
|
|
|
|
|
|
|
|
actual := CompareVersions(each.ver1, each.ver2)
|
|
|
|
|
|
|
|
assert.Equal(t, each.out, actual)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestCustomCompareVersions(t *testing.T) {
|
|
|
|
func TestCustomCompareVersions(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
cases := []struct {
|
|
|
|
ver1 string
|
|
|
|
ver1 string
|
|
|
@ -53,7 +30,7 @@ func TestCustomCompareVersions(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
for _, each := range cases {
|
|
|
|
for _, each := range cases {
|
|
|
|
t.Run(each.ver1, func(t *testing.T) {
|
|
|
|
t.Run(each.ver1, func(t *testing.T) {
|
|
|
|
actual := CustomCompareVersions(each.ver1, each.ver2, each.operator)
|
|
|
|
actual := CompareVersions(each.ver1, each.ver2, each.operator)
|
|
|
|
assert.Equal(t, each.out, actual)
|
|
|
|
assert.Equal(t, each.out, actual)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|