diff --git a/core/utils/version.go b/core/utils/version.go index bcd35667..cf43157a 100644 --- a/core/utils/version.go +++ b/core/utils/version.go @@ -10,14 +10,15 @@ func Compare(v1, v2 string) int { replaceMap := map[string]string{"V": "", "v": "", "-": "."} for k, v := range replaceMap { if strings.Contains(v1, k) { - strings.Replace(v1, k, v, -1) + v1 = strings.Replace(v1, k, v, -1) } if strings.Contains(v2, k) { - strings.Replace(v2, k, v, -1) + v2 = strings.Replace(v2, k, v, -1) } } verStr1 := strings.Split(v1, ".") verStr2 := strings.Split(v2, ".") + ver1 := strSlice2IntSlice(verStr1) ver2 := strSlice2IntSlice(verStr2) @@ -64,8 +65,8 @@ func strSlice2IntSlice(strs []string) []int64 { return retInt } -//operator compare returns true if the first field and the second field are equal else false -func CompareVersions(v1, v2, operator string) bool { +//operator compare returns true if the first field and the third field equation holds else false +func CompareVersions(v1, operator, v2 string) bool { com := Compare(v1, v2) switch operator { case "==": diff --git a/core/utils/version_test.go b/core/utils/version_test.go index 80875650..90e75213 100644 --- a/core/utils/version_test.go +++ b/core/utils/version_test.go @@ -15,7 +15,7 @@ func TestCustomCompareVersions(t *testing.T) { }{ {"1", "1.0.1", ">", false}, {"1", "0.9.9", ">", true}, - {"1", "1-0.1", "<", true}, + {"1", "1.0-1", "<", true}, {"1.0.1", "1-0.1", "<", false}, {"1.0.1", "1.0.1", "==", true}, {"1.0.1", "1.0.2", "==", false}, @@ -30,7 +30,7 @@ func TestCustomCompareVersions(t *testing.T) { for _, each := range cases { t.Run(each.ver1, func(t *testing.T) { - actual := CompareVersions(each.ver1, each.ver2, each.operator) + actual := CompareVersions(each.ver1, each.operator, each.ver2) assert.Equal(t, each.out, actual) }) }