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

Function TestNewCmdList

pkg/cmd/variable/list/list_test.go:24–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestNewCmdList(t *testing.T) {
25 tests := []struct {
26 name string
27 cli string
28 wants ListOptions
29 }{
30 {
31 name: "repo",
32 cli: "",
33 wants: ListOptions{
34 OrgName: "",
35 },
36 },
37 {
38 name: "org",
39 cli: "-oUmbrellaCorporation",
40 wants: ListOptions{
41 OrgName: "UmbrellaCorporation",
42 },
43 },
44 {
45 name: "env",
46 cli: "-eDevelopment",
47 wants: ListOptions{
48 EnvName: "Development",
49 },
50 },
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 ios, _, _, _ := iostreams.Test()
56 f := &cmdutil.Factory{
57 IOStreams: ios,
58 }
59
60 argv, err := shlex.Split(tt.cli)
61 assert.NoError(t, err)
62
63 var gotOpts *ListOptions
64 cmd := NewCmdList(f, func(opts *ListOptions) error {
65 gotOpts = opts
66 return nil
67 })
68 cmd.SetArgs(argv)
69 cmd.SetIn(&bytes.Buffer{})
70 cmd.SetOut(&bytes.Buffer{})
71 cmd.SetErr(&bytes.Buffer{})
72
73 _, err = cmd.ExecuteC()
74 assert.NoError(t, err)
75
76 assert.Equal(t, tt.wants.OrgName, gotOpts.OrgName)
77 assert.Equal(t, tt.wants.EnvName, gotOpts.EnvName)
78 })
79 }
80}
81

Callers

nothing calls this directly

Calls 4

TestFunction · 0.92
EqualMethod · 0.80
NewCmdListFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected