MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdList

Function TestNewCmdList

pkg/cmd/issue/list/list_test.go:28–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestNewCmdList(t *testing.T) {
29 tests := []struct {
30 name string
31 cli string
32 wantsErr bool
33 wants ListOptions
34 }{
35 {
36 name: "type flag",
37 cli: "--type Bug",
38 wants: ListOptions{
39 IssueType: "Bug",
40 State: "open",
41 LimitResults: 30,
42 },
43 },
44 }
45
46 for _, tt := range tests {
47 t.Run(tt.name, func(t *testing.T) {
48 f := &cmdutil.Factory{}
49 var gotOpts *ListOptions
50 cmd := NewCmdList(f, func(opts *ListOptions) error {
51 gotOpts = opts
52 return nil
53 })
54 argv, err := shlex.Split(tt.cli)
55 require.NoError(t, err)
56 cmd.SetArgs(argv)
57 cmd.SetIn(&bytes.Buffer{})
58 cmd.SetOut(io.Discard)
59 cmd.SetErr(io.Discard)
60
61 _, err = cmd.ExecuteC()
62 if tt.wantsErr {
63 require.Error(t, err)
64 return
65 }
66 require.NoError(t, err)
67 require.NotNil(t, gotOpts)
68
69 assert.Equal(t, tt.wants.IssueType, gotOpts.IssueType)
70 assert.Equal(t, tt.wants.State, gotOpts.State)
71 assert.Equal(t, tt.wants.LimitResults, gotOpts.LimitResults)
72 })
73 }
74}
75
76func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
77 ios, _, stdout, stderr := iostreams.Test()

Callers

nothing calls this directly

Calls 4

EqualMethod · 0.80
NewCmdListFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…