From 9e4687d3c58482afa6f11cf528e390aa927bc02d Mon Sep 17 00:00:00 2001 From: derailed Date: Tue, 5 Mar 2024 11:41:54 -0700 Subject: [PATCH] [Maint] semver pkg change --- cmd/root.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- internal/cache/cluster.go | 2 +- internal/cache/cluster_test.go | 8 ++++---- internal/dag/cluster.go | 2 +- internal/dag/helper_test.go | 16 ++++++++-------- internal/dag/helpers.go | 6 +++--- internal/lint/cluster.go | 4 ++-- internal/lint/cluster_test.go | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 14b2c668..57fd9b74 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -84,7 +84,7 @@ func bomb(err error) { if err == nil { return } - panic(fmt.Sprintf("💥 %s\n", report.Colorize(err.Error(), report.ColorRed))) + panic(fmt.Errorf("💥 %s\n", report.Colorize(err.Error(), report.ColorRed))) } func initPopeyeFlags() { diff --git a/go.mod b/go.mod index a12e3c93..47eac6e3 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/derailed/popeye go 1.21.1 require ( - github.com/Masterminds/semver v1.5.0 github.com/aws/aws-sdk-go v1.35.21 + github.com/blang/semver/v4 v4.0.0 github.com/fvbommel/sortorder v1.0.1 github.com/hashicorp/go-memdb v1.3.4 github.com/prometheus/client_golang v1.17.0 diff --git a/go.sum b/go.sum index 84a64373..49f56512 100644 --- a/go.sum +++ b/go.sum @@ -2,12 +2,12 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/aws/aws-sdk-go v1.35.21 h1:6cMeHzcca+0uweOpUonDYv4DsPp9Qa9PTMYxH+VqDkY= github.com/aws/aws-sdk-go v1.35.21/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= diff --git a/internal/cache/cluster.go b/internal/cache/cluster.go index fc75801c..83478f47 100644 --- a/internal/cache/cluster.go +++ b/internal/cache/cluster.go @@ -6,7 +6,7 @@ package cache import ( "errors" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" ) // ClusterKey tracks Cluster resource references diff --git a/internal/cache/cluster_test.go b/internal/cache/cluster_test.go index 4d9f95c7..baa84190 100644 --- a/internal/cache/cluster_test.go +++ b/internal/cache/cluster_test.go @@ -6,7 +6,7 @@ package cache_test import ( "testing" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" "github.com/derailed/popeye/internal/cache" "github.com/rs/zerolog" "github.com/stretchr/testify/assert" @@ -17,11 +17,11 @@ func init() { } func TestCluster(t *testing.T) { - v, err := semver.NewVersion("1.9") + v, err := semver.ParseTolerant("1.9") assert.NoError(t, err) - c := cache.NewCluster(v) + c := cache.NewCluster(&v) v1, err := c.ListVersion() assert.NoError(t, err) - assert.Equal(t, v, v1) + assert.Equal(t, &v, v1) } diff --git a/internal/dag/cluster.go b/internal/dag/cluster.go index 5d57a705..8abfd598 100644 --- a/internal/dag/cluster.go +++ b/internal/dag/cluster.go @@ -6,7 +6,7 @@ package dag import ( "context" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" ) // ListVersion return server api version. diff --git a/internal/dag/helper_test.go b/internal/dag/helper_test.go index c96ca36a..cee4cd61 100644 --- a/internal/dag/helper_test.go +++ b/internal/dag/helper_test.go @@ -5,25 +5,24 @@ package dag import ( "errors" - "fmt" "testing" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/version" ) func TestParseVers(t *testing.T) { - v, _ := semver.NewVersion("1.28") + v, _ := semver.ParseTolerant("1.28") uu := map[string]struct { info version.Info err error - ver *semver.Version + ver semver.Version }{ "empty": { - err: fmt.Errorf(`semver parse failed for "." (""|""): %w`, errors.New("Invalid Semantic Version")), + err: errors.New(`semver parse failed for "." (""|""): strconv.ParseUint: parsing "": invalid syntax`), }, "happy": { info: version.Info{Major: "1", Minor: "28"}, @@ -39,9 +38,10 @@ func TestParseVers(t *testing.T) { u := uu[k] t.Run(k, func(t *testing.T) { v, err := ParseVersion(&u.info) - assert.Equal(t, u.err, err) - if err == nil { - assert.Equal(t, u.ver, v) + if err != nil { + assert.Equal(t, u.err.Error(), err.Error()) + } else { + assert.Equal(t, &u.ver, v) } }) } diff --git a/internal/dag/helpers.go b/internal/dag/helpers.go index d18b7022..f1b2e67a 100644 --- a/internal/dag/helpers.go +++ b/internal/dag/helpers.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" "github.com/derailed/popeye/internal" "github.com/derailed/popeye/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -21,12 +21,12 @@ func ParseVersion(info *version.Info) (*semver.Version, error) { return nil, fmt.Errorf("no cluster version available") } v := strings.TrimSuffix(info.Major+"."+info.Minor, "+") - rev, err := semver.NewVersion(v) + rev, err := semver.ParseTolerant(v) if err != nil { err = fmt.Errorf("semver parse failed for %q (%q|%q): %w", v, info.Major, info.Minor, err) } - return rev, err + return &rev, err } func mustExtractFactory(ctx context.Context) types.Factory { diff --git a/internal/lint/cluster.go b/internal/lint/cluster.go index d77ad9c8..087a6d05 100644 --- a/internal/lint/cluster.go +++ b/internal/lint/cluster.go @@ -6,7 +6,7 @@ package lint import ( "context" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" "github.com/derailed/popeye/internal" "github.com/derailed/popeye/internal/issues" ) @@ -50,7 +50,7 @@ func (c *Cluster) checkVersion(ctx context.Context) error { } ctx = internal.WithSpec(ctx, specFor("Version", nil)) - if rev.Major() != tolerableMajor || rev.Minor() < tolerableMinor { + if rev.Major != tolerableMajor || rev.Minor < tolerableMinor { c.AddCode(ctx, 405) } else { c.AddCode(ctx, 406) diff --git a/internal/lint/cluster_test.go b/internal/lint/cluster_test.go index 84ffafb8..b35528c3 100644 --- a/internal/lint/cluster_test.go +++ b/internal/lint/cluster_test.go @@ -6,7 +6,7 @@ package lint import ( "testing" - "github.com/Masterminds/semver" + "github.com/blang/semver/v4" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/version"