1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-07 00:17:13 +00:00
kyverno/cmd/cli/kubectl-kyverno/commands/version/command_test.go

37 lines
695 B
Go
Raw Normal View History

package version
import (
"bytes"
"io"
"strings"
"testing"
"github.com/kyverno/kyverno/pkg/version"
"github.com/stretchr/testify/assert"
)
func TestCommand(t *testing.T) {
version.BuildVersion = "test"
cmd := Command()
assert.NotNil(t, cmd)
b := bytes.NewBufferString("")
cmd.SetOut(b)
err := cmd.Execute()
assert.NoError(t, err)
out, err := io.ReadAll(b)
assert.NoError(t, err)
expected := `
Version: test
Time: ---
Git commit ID: ---`
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out)))
}
func TestCommandWithArgs(t *testing.T) {
cmd := Command()
assert.NotNil(t, cmd)
cmd.SetArgs([]string{"test"})
err := cmd.Execute()
assert.Error(t, err)
}