From b8be6fae3a437370728e04291e164b06d478aef6 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Thu, 16 Mar 2023 15:57:47 +0100 Subject: [PATCH] fix(cmd): compatibility check when not a semver --- pkg/cmd/version.go | 3 +++ pkg/cmd/version_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 338da99be5..0dfabbc08a 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -183,6 +183,9 @@ func operatorVersion(ctx context.Context, c client.Client, namespace string) (st } func compatibleVersions(aVersion, bVersion string, cmd *cobra.Command) bool { + if aVersion == bVersion { + return true + } a, err := semver.NewVersion(aVersion) if err != nil { fmt.Fprintln(cmd.ErrOrStderr(), "Could not parse '"+aVersion+"' (error:", err.Error()+")") diff --git a/pkg/cmd/version_test.go b/pkg/cmd/version_test.go index 69951c442d..383fe9cf93 100644 --- a/pkg/cmd/version_test.go +++ b/pkg/cmd/version_test.go @@ -86,3 +86,9 @@ func TestCompatibleVersions(t *testing.T) { assert.Equal(t, false, compatibleVersions("1.3.0", "dsadsa", rootCmd)) assert.Equal(t, false, compatibleVersions("dsadsa", "1.3.4", rootCmd)) } + +func TestCompatibleVersionsNonSemver(t *testing.T) { + _, rootCmd, _ := initializeVersionCmdOptions(t) + assert.Equal(t, true, compatibleVersions("1.3.0.special-version", "1.3.0.special-version", rootCmd)) + assert.Equal(t, false, compatibleVersions("1.3.1.special-version", "1.3.0.special-version", rootCmd)) +}