MCPcopy
hub / github.com/cli/cli / TestNewCmdConfigList

Function TestNewCmdConfigList

pkg/cmd/config/list/list_test.go:17–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestNewCmdConfigList(t *testing.T) {
18 tests := []struct {
19 name string
20 input string
21 output ListOptions
22 wantsErr bool
23 }{
24 {
25 name: "no arguments",
26 input: "",
27 output: ListOptions{},
28 wantsErr: false,
29 },
30 {
31 name: "list with host",
32 input: "--host HOST.com",
33 output: ListOptions{Hostname: "HOST.com"},
34 wantsErr: false,
35 },
36 }
37
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 f := &cmdutil.Factory{
41 Config: func() (gh.Config, error) {
42 return config.NewBlankConfig(), nil
43 },
44 }
45
46 argv, err := shlex.Split(tt.input)
47 assert.NoError(t, err)
48
49 var gotOpts *ListOptions
50 cmd := NewCmdConfigList(f, func(opts *ListOptions) error {
51 gotOpts = opts
52 return nil
53 })
54 cmd.Flags().BoolP("help", "x", false, "")
55
56 cmd.SetArgs(argv)
57 cmd.SetIn(&bytes.Buffer{})
58 cmd.SetOut(&bytes.Buffer{})
59 cmd.SetErr(&bytes.Buffer{})
60
61 _, err = cmd.ExecuteC()
62 if tt.wantsErr {
63 assert.Error(t, err)
64 return
65 }
66
67 assert.NoError(t, err)
68 assert.Equal(t, tt.output.Hostname, gotOpts.Hostname)
69 })
70 }
71}
72
73func Test_listRun(t *testing.T) {
74 tests := []struct {

Callers

nothing calls this directly

Calls 5

NewBlankConfigFunction · 0.92
NewCmdConfigListFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected