MCPcopy
hub / github.com/cli/cli / TestNewCmdConfigSet

Function TestNewCmdConfigSet

pkg/cmd/config/set/set_test.go:15–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

StubWriteConfigFunction · 0.92
NewBlankConfigFunction · 0.92
NewCmdConfigSetFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected