MCPcopy Index your code
hub / github.com/cli/cli / TestNewCmdList

Function TestNewCmdList

pkg/cmd/org/list/list_test.go:18–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestNewCmdList(t *testing.T) {
19 tests := []struct {
20 name string
21 cli string
22 wants ListOptions
23 wantsErr string
24 }{
25 {
26 name: "no arguments",
27 cli: "",
28 wants: ListOptions{
29 Limit: 30,
30 },
31 },
32 {
33 name: "with limit",
34 cli: "-L 101",
35 wants: ListOptions{
36 Limit: 101,
37 },
38 },
39 {
40 name: "too many arguments",
41 cli: "123 456",
42 wantsErr: "accepts at most 1 arg(s), received 2",
43 },
44 {
45 name: "invalid limit",
46 cli: "-L 0",
47 wantsErr: "invalid limit: 0",
48 },
49 }
50
51 for _, tt := range tests {
52 t.Run(tt.name, func(t *testing.T) {
53 f := &cmdutil.Factory{}
54
55 argv, err := shlex.Split(tt.cli)
56 assert.NoError(t, err)
57
58 var gotOpts *ListOptions
59 cmd := NewCmdList(f, func(opts *ListOptions) error {
60 gotOpts = opts
61 return nil
62 })
63 cmd.SetArgs(argv)
64 cmd.SetIn(&bytes.Buffer{})
65 cmd.SetOut(&bytes.Buffer{})
66 cmd.SetErr(&bytes.Buffer{})
67
68 _, err = cmd.ExecuteC()
69 if tt.wantsErr != "" {
70 assert.EqualError(t, err, tt.wantsErr)
71 return
72 }
73
74 assert.NoError(t, err)
75 assert.Equal(t, tt.wants.Limit, gotOpts.Limit)

Callers

nothing calls this directly

Calls 3

EqualMethod · 0.80
NewCmdListFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected