|
| 1 | +package list |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "strings" |
| 6 | + "testing" |
| 7 | + |
| 8 | + . "github.com/onsi/gomega" |
| 9 | + |
| 10 | + "k8s.io/cli-runtime/pkg/genericclioptions" |
| 11 | +) |
| 12 | + |
| 13 | +func TestGetAccountCmdComplete(t *testing.T) { |
| 14 | + g := NewGomegaWithT(t) |
| 15 | + streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} |
| 16 | + kubeFlags := genericclioptions.NewConfigFlags(false) |
| 17 | + testCases := []struct { |
| 18 | + title string |
| 19 | + option *listAccountOptions |
| 20 | + errExpected bool |
| 21 | + errContent string |
| 22 | + }{ |
| 23 | + { |
| 24 | + title: "incorrect state", |
| 25 | + option: &listAccountOptions{ |
| 26 | + state: "foo", |
| 27 | + }, |
| 28 | + errExpected: true, |
| 29 | + errContent: "unsupported account state foo", |
| 30 | + }, |
| 31 | + { |
| 32 | + title: "empty state", |
| 33 | + option: &listAccountOptions{ |
| 34 | + state: "", |
| 35 | + flags: kubeFlags, |
| 36 | + }, |
| 37 | + errExpected: false, |
| 38 | + }, |
| 39 | + { |
| 40 | + title: "all state", |
| 41 | + option: &listAccountOptions{ |
| 42 | + state: "all", |
| 43 | + flags: kubeFlags, |
| 44 | + }, |
| 45 | + errExpected: false, |
| 46 | + }, |
| 47 | + { |
| 48 | + title: "Ready state", |
| 49 | + option: &listAccountOptions{ |
| 50 | + state: "Ready", |
| 51 | + flags: kubeFlags, |
| 52 | + }, |
| 53 | + errExpected: false, |
| 54 | + }, |
| 55 | + { |
| 56 | + title: "bad reuse", |
| 57 | + option: &listAccountOptions{ |
| 58 | + reused: "foo", |
| 59 | + }, |
| 60 | + errExpected: true, |
| 61 | + errContent: "unsupported reused status filter foo", |
| 62 | + }, |
| 63 | + { |
| 64 | + title: "bad reused status", |
| 65 | + option: &listAccountOptions{ |
| 66 | + reused: "foo", |
| 67 | + }, |
| 68 | + errExpected: true, |
| 69 | + errContent: "unsupported reused status filter foo", |
| 70 | + }, |
| 71 | + { |
| 72 | + title: "bad claimed status", |
| 73 | + option: &listAccountOptions{ |
| 74 | + claimed: "foo", |
| 75 | + }, |
| 76 | + errExpected: true, |
| 77 | + errContent: "unsupported claimed status filter foo", |
| 78 | + }, |
| 79 | + { |
| 80 | + title: "good reused true", |
| 81 | + option: &listAccountOptions{ |
| 82 | + reused: "true", |
| 83 | + flags: kubeFlags, |
| 84 | + }, |
| 85 | + errExpected: false, |
| 86 | + }, |
| 87 | + { |
| 88 | + title: "good claim", |
| 89 | + option: &listAccountOptions{ |
| 90 | + claimed: "false", |
| 91 | + flags: kubeFlags, |
| 92 | + }, |
| 93 | + errExpected: false, |
| 94 | + }, |
| 95 | + { |
| 96 | + title: "success", |
| 97 | + option: &listAccountOptions{ |
| 98 | + state: "Ready", |
| 99 | + reused: "true", |
| 100 | + claimed: "false", |
| 101 | + flags: kubeFlags, |
| 102 | + }, |
| 103 | + errExpected: false, |
| 104 | + }, |
| 105 | + } |
| 106 | + |
| 107 | + for _, tc := range testCases { |
| 108 | + t.Run(tc.title, func(t *testing.T) { |
| 109 | + cmd := newCmdListAccount(streams, kubeFlags) |
| 110 | + err := tc.option.complete(cmd, nil) |
| 111 | + if tc.errExpected { |
| 112 | + g.Expect(err).Should(HaveOccurred()) |
| 113 | + if tc.errContent != "" { |
| 114 | + g.Expect(true).Should(Equal(strings.Contains(err.Error(), tc.errContent))) |
| 115 | + } |
| 116 | + } else { |
| 117 | + g.Expect(err).ShouldNot(HaveOccurred()) |
| 118 | + } |
| 119 | + }) |
| 120 | + } |
| 121 | +} |
0 commit comments