...
1
16
17 package version
18
19 import (
20 "strings"
21 "testing"
22
23 "github.com/spf13/cobra"
24
25 "k8s.io/cli-runtime/pkg/genericiooptions"
26
27 cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
28 )
29
30 func TestNewCmdVersionClientVersion(t *testing.T) {
31 tf := cmdtesting.NewTestFactory().WithNamespace("test")
32 defer tf.Cleanup()
33 streams, _, buf, _ := genericiooptions.NewTestIOStreams()
34 o := NewOptions(streams)
35 if err := o.Complete(tf, &cobra.Command{}, nil); err != nil {
36 t.Errorf("Unexpected error: %v", err)
37 }
38 if err := o.Validate(); err != nil {
39 t.Errorf("Unexpected error: %v", err)
40 }
41 if err := o.Complete(tf, &cobra.Command{}, []string{"extraParameter0"}); err != nil {
42 t.Errorf("Unexpected error: %v", err)
43 }
44 if err := o.Validate(); !strings.Contains(err.Error(), "extra arguments") {
45 t.Errorf("Unexpected error: should fail to validate the args length greater than 0")
46 }
47 if err := o.Run(); err != nil {
48 t.Errorf("Cannot execute version command: %v", err)
49 }
50 if !strings.Contains(buf.String(), "Client Version") {
51 t.Errorf("unexpected output: %s", buf.String())
52 }
53 }
54
View as plain text