Skip to content

Commit

Permalink
fix(cmd): compatibility check when not a semver
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Mar 16, 2023
1 parent bf4aad7 commit 16d2769
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()+")")
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 16d2769

Please sign in to comment.