1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: improve cli version command and add tests (#8336)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-09-11 22:36:35 +02:00 committed by GitHub
parent 3967adde6e
commit 67cfa341a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -14,6 +14,7 @@ func Command() *cobra.Command {
Short: command.FormatDescription(true, websiteUrl, false, description...), Short: command.FormatDescription(true, websiteUrl, false, description...),
Long: command.FormatDescription(false, websiteUrl, false, description...), Long: command.FormatDescription(false, websiteUrl, false, description...),
Example: command.FormatExamples(examples...), Example: command.FormatExamples(examples...),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("Version: %s\n", version.Version()) fmt.Printf("Version: %s\n", version.Version())
fmt.Printf("Time: %s\n", version.Time()) fmt.Printf("Time: %s\n", version.Time())

View file

@ -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)
}