fix: parse Go RC version (#4319)
This commit is contained in:
parent
553161d96a
commit
ad4a6b2c03
@ -991,7 +991,7 @@ func trimGoVersion(v string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
exp := regexp.MustCompile(`(\d\.\d+)\.\d+`)
|
exp := regexp.MustCompile(`(\d\.\d+)(?:\.\d+|[a-z]+\d)`)
|
||||||
|
|
||||||
if exp.MatchString(v) {
|
if exp.MatchString(v) {
|
||||||
return exp.FindStringSubmatch(v)[1]
|
return exp.FindStringSubmatch(v)[1]
|
||||||
|
56
pkg/lint/lintersdb/manager_test.go
Normal file
56
pkg/lint/lintersdb/manager_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package lintersdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_trimGoVersion(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
version string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "patched version",
|
||||||
|
version: "1.22.0",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "minor version",
|
||||||
|
version: "1.22",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "RC version",
|
||||||
|
version: "1.22rc1",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "alpha version",
|
||||||
|
version: "1.22alpha1",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "beta version",
|
||||||
|
version: "1.22beta1",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "semver RC version",
|
||||||
|
version: "1.22.0-rc1",
|
||||||
|
expected: "1.22",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
test := test
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
version := trimGoVersion(test.version)
|
||||||
|
assert.Equal(t, test.expected, version)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user