Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse Go RC version #4319

Merged
merged 2 commits into from
Jan 14, 2024
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",
ldez marked this conversation as resolved.
Show resolved Hide resolved
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