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

Function TestNewCmdEdit

pkg/cmd/label/edit_test.go:16–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNewCmdEdit(t *testing.T) {
17 tests := []struct {
18 name string
19 input string
20 output editOptions
21 wantErr bool
22 errMsg string
23 }{
24 {
25 name: "no argument",
26 input: "",
27 wantErr: true,
28 errMsg: "cannot update label: name argument required",
29 },
30 {
31 name: "name argument",
32 input: "test",
33 wantErr: true,
34 errMsg: "specify at least one of `--color`, `--description`, or `--name`",
35 },
36 {
37 name: "description flag",
38 input: "test --description 'some description'",
39 output: editOptions{Name: "test", Description: "some description"},
40 },
41 {
42 name: "color flag",
43 input: "test --color FFFFFF",
44 output: editOptions{Name: "test", Color: "FFFFFF"},
45 },
46 {
47 name: "color flag with pound sign",
48 input: "test --color '#AAAAAA'",
49 output: editOptions{Name: "test", Color: "AAAAAA"},
50 },
51 {
52 name: "name flag",
53 input: "test --name test1",
54 output: editOptions{Name: "test", NewName: "test1"},
55 },
56 }
57
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 io, _, _, _ := iostreams.Test()
61 f := &cmdutil.Factory{
62 IOStreams: io,
63 }
64 argv, err := shlex.Split(tt.input)
65 assert.NoError(t, err)
66 var gotOpts *editOptions
67 cmd := newCmdEdit(f, func(opts *editOptions) error {
68 gotOpts = opts
69 return nil
70 })
71 cmd.SetArgs(argv)
72 cmd.SetIn(&bytes.Buffer{})
73 cmd.SetOut(&bytes.Buffer{})

Callers

nothing calls this directly

Calls 4

TestFunction · 0.92
newCmdEditFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected