Enable stylecheck linter and resolve found issues.

Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
This commit is contained in:
Xun Jiang
2023-04-25 13:50:52 +08:00
parent 980106dc39
commit bbc1e2e151
40 changed files with 215 additions and 227 deletions

View File

@@ -29,19 +29,19 @@ import (
// minor
// patch
// prerelease (this will be alpha/beta/rc followed by a ".", followed by 1 or more digits (alpha.5)
var release_regex *regexp.Regexp = regexp.MustCompile(`^v(?P<major>[[:digit:]]+)\.(?P<minor>[[:digit:]]+)\.(?P<patch>[[:digit:]]+)(-{1}(?P<prerelease>(alpha|beta|rc)\.[[:digit:]]+))*`)
var releaseRegex = regexp.MustCompile(`^v(?P<major>[[:digit:]]+)\.(?P<minor>[[:digit:]]+)\.(?P<patch>[[:digit:]]+)(-{1}(?P<prerelease>(alpha|beta|rc)\.[[:digit:]]+))*`)
// This small program exists because checking the VELERO_VERSION rules in bash is difficult, and difficult to test for correctness.
// Calling it with --verify will verify whether or not the VELERO_VERSION environment variable is a valid version string, without parsing for its components.
// Calling it without --verify will try to parse the version into its component pieces.
func main() {
velero_version := os.Getenv("VELERO_VERSION")
veleroVersion := os.Getenv("VELERO_VERSION")
submatches := reSubMatchMap(release_regex, velero_version)
submatches := reSubMatchMap(releaseRegex, veleroVersion)
// Didn't match the regex, exit.
if len(submatches) == 0 {
fmt.Printf("VELERO_VERSION of %s was not valid. Please correct the value and retry.", velero_version)
fmt.Printf("VELERO_VERSION of %s was not valid. Please correct the value and retry.", veleroVersion)
os.Exit(1)
}

View File

@@ -56,7 +56,7 @@ func TestRegexMatching(t *testing.T) {
for _, test := range tests {
name := fmt.Sprintf("Testing version string %s", test.version)
t.Run(name, func(t *testing.T) {
results := reSubMatchMap(release_regex, test.version)
results := reSubMatchMap(releaseRegex, test.version)
if len(results) == 0 && test.expectMatch {
t.Fail()