From d297a3bc705a226201163d8007f08aa198547a7c Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Tue, 14 Nov 2023 13:27:08 -0600 Subject: [PATCH] Patch incorrect conversion between uint64 and int64 (#7048) The semver package unnecessarily uses uint64. This alters it to use int64 alleviating the problem. --- pkg/semver/semver.go | 10 +++++----- pkg/validations/cluster_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/semver/semver.go b/pkg/semver/semver.go index 17d42a545ea8..71ab11aa6238 100644 --- a/pkg/semver/semver.go +++ b/pkg/semver/semver.go @@ -11,7 +11,7 @@ const semverRegex = `^v?(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P var semverRegexp = regexp.MustCompile(semverRegex) type Version struct { - Major, Minor, Patch uint64 + Major, Minor, Patch int64 Prerelease, Buildmetadata string } @@ -29,15 +29,15 @@ func New(version string) (*Version, error) { v := &Version{} var err error - v.Major, err = strconv.ParseUint(namedGroups["major"], 10, 64) + v.Major, err = strconv.ParseInt(namedGroups["major"], 10, 64) if err != nil { return nil, fmt.Errorf("invalid major version in semver %s: %v", version, err) } - v.Minor, err = strconv.ParseUint(namedGroups["minor"], 10, 64) + v.Minor, err = strconv.ParseInt(namedGroups["minor"], 10, 64) if err != nil { return nil, fmt.Errorf("invalid minor version in semver %s: %v", version, err) } - v.Patch, err = strconv.ParseUint(namedGroups["patch"], 10, 64) + v.Patch, err = strconv.ParseInt(namedGroups["patch"], 10, 64) if err != nil { return nil, fmt.Errorf("invalid patch version in semver %s: %v", version, err) } @@ -93,7 +93,7 @@ func (v *Version) String() string { return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch) } -func compare(i, i2 uint64) int { +func compare(i, i2 int64) int { if i > i2 { return 1 } else if i < i2 { diff --git a/pkg/validations/cluster_test.go b/pkg/validations/cluster_test.go index 252d5ae3711c..d74394eb2eb5 100644 --- a/pkg/validations/cluster_test.go +++ b/pkg/validations/cluster_test.go @@ -328,13 +328,13 @@ func TestValidateEksaVersion(t *testing.T) { }, { name: "Bad Cluster version", - wantErr: fmt.Errorf("parsing cluster eksa version: invalid major version in semver invalid: strconv.ParseUint: parsing \"\": invalid syntax"), + wantErr: fmt.Errorf("parsing cluster eksa version: invalid major version in semver invalid: strconv.ParseInt: parsing \"\": invalid syntax"), version: &badVersion, cliVersion: "v0.0.0-dev", }, { name: "Bad CLI version", - wantErr: fmt.Errorf("parsing eksa cli version: invalid major version in semver badvalue: strconv.ParseUint: parsing \"\": invalid syntax"), + wantErr: fmt.Errorf("parsing eksa cli version: invalid major version in semver badvalue: strconv.ParseInt: parsing \"\": invalid syntax"), version: &v, cliVersion: "badvalue", },