diff --git a/cmd/cli/kubectl-kyverno/commands/version/command.go b/cmd/cli/kubectl-kyverno/commands/version/command.go index 31bcbc2857..d5658a09e8 100644 --- a/cmd/cli/kubectl-kyverno/commands/version/command.go +++ b/cmd/cli/kubectl-kyverno/commands/version/command.go @@ -14,6 +14,7 @@ func Command() *cobra.Command { Short: command.FormatDescription(true, websiteUrl, false, description...), Long: command.FormatDescription(false, websiteUrl, false, description...), Example: command.FormatExamples(examples...), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { fmt.Printf("Version: %s\n", version.Version()) fmt.Printf("Time: %s\n", version.Time()) diff --git a/cmd/cli/kubectl-kyverno/commands/version/command_test.go b/cmd/cli/kubectl-kyverno/commands/version/command_test.go new file mode 100644 index 0000000000..f832c59290 --- /dev/null +++ b/cmd/cli/kubectl-kyverno/commands/version/command_test.go @@ -0,0 +1,20 @@ +package version + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCommand(t *testing.T) { + cmd := Command() + err := cmd.Execute() + assert.NoError(t, err) +} + +func TestCommandWithArgs(t *testing.T) { + cmd := Command() + cmd.SetArgs([]string{"test"}) + err := cmd.Execute() + assert.Error(t, err) +}