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

Function TestNewCmdList

pkg/cmd/agent-task/list/list_test.go:21–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestNewCmdList(t *testing.T) {
22 tests := []struct {
23 name string
24 args string
25 wantOpts ListOptions
26 wantErr string
27 }{
28 {
29 name: "no arguments",
30 wantOpts: ListOptions{
31 Limit: defaultLimit,
32 },
33 },
34 {
35 name: "custom limit",
36 args: "--limit 15",
37 wantOpts: ListOptions{
38 Limit: 15,
39 },
40 },
41 {
42 name: "invalid limit",
43 args: "--limit 0",
44 wantErr: "invalid limit: 0",
45 },
46 {
47 name: "negative limit",
48 args: "--limit -5",
49 wantErr: "invalid limit: -5",
50 },
51 {
52 name: "web flag",
53 args: "--web",
54 wantOpts: ListOptions{
55 Limit: defaultLimit,
56 Web: true,
57 },
58 },
59 }
60
61 for _, tt := range tests {
62 t.Run(tt.name, func(t *testing.T) {
63 ios, _, _, _ := iostreams.Test()
64 f := &cmdutil.Factory{
65 IOStreams: ios,
66 }
67
68 var gotOpts *ListOptions
69 cmd := NewCmdList(f, func(opts *ListOptions) error { gotOpts = opts; return nil })
70
71 argv, err := shlex.Split(tt.args)
72 require.NoError(t, err)
73 cmd.SetArgs(argv)
74
75 cmd.SetIn(&bytes.Buffer{})
76 cmd.SetOut(io.Discard)
77 cmd.SetErr(io.Discard)
78

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
ContainsMethod · 0.80
EqualMethod · 0.80
NewCmdListFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected