1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

fix(global): version compare

#877
This commit is contained in:
wdvxdr 2021-05-05 15:08:14 +08:00
parent f0a472bc3c
commit 4716d79a7e
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
6 changed files with 49 additions and 2 deletions

View File

@ -9,6 +9,15 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
- name: Tests
run: |
run: go test $(go list ./...)
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:

View File

@ -9,6 +9,15 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
- name: Tests
run: |
run: go test $(go list ./...)
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:

27
global/all_test.go Normal file
View File

@ -0,0 +1,27 @@
package global
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersionNameCompare(t *testing.T) {
var tests = [...]struct {
current string
remote string
expected bool
}{
{"v0.9.29-fix2", "v0.9.29-fix2", false},
{"v0.9.29-fix1", "v0.9.29-fix2", true},
{"v0.9.29-fix2", "v0.9.29-fix1", false},
{"v0.9.29-fix2", "v0.9.30", true},
{"v1.0.0-beta1", "v0.9.40-fix5", false}, // issue #877
}
for i := 0; i < len(tests); i++ {
t.Run("test case "+strconv.Itoa(i), func(t *testing.T) {
assert.Equal(t, tests[i].expected, VersionNameCompare(tests[i].current, tests[i].remote))
})
}
}

View File

@ -79,8 +79,8 @@ func VersionNameCompare(current, remote string) bool {
for i := 0; i < int(math.Min(float64(len(cur)), float64(len(re)))); i++ {
curSub, _ := strconv.Atoi(cur[i][0])
reSub, _ := strconv.Atoi(re[i][0])
if curSub < reSub {
return true
if curSub != reSub {
return curSub < reSub
}
}
return len(cur) < len(re)

1
go.mod
View File

@ -19,6 +19,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/syndtr/goleveldb v1.0.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tidwall/gjson v1.7.5

1
go.sum
View File

@ -110,6 +110,7 @@ github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=