Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
56 changes: 56 additions & 0 deletions pkg/lint/lintersdb/manager_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}