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

Function TestNewCmdConfigGet

pkg/cmd/config/get/get_test.go:16–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected