fix: parse Go RC version (#4319)

This commit is contained in:
Ludovic Fernandez 2024-01-14 21:22:57 +01:00 committed by GitHub
parent 553161d96a
commit ad4a6b2c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 1 deletions

View File

@ -991,7 +991,7 @@ func trimGoVersion(v string) string {
return ""
}
exp := regexp.MustCompile(`(\d\.\d+)\.\d+`)
exp := regexp.MustCompile(`(\d\.\d+)(?:\.\d+|[a-z]+\d)`)
if exp.MatchString(v) {
return exp.FindStringSubmatch(v)[1]

View 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)
})
}
}