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

Function TestNewCmdList

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

Source from the content-addressed store, hash-verified

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

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