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

Function TestNewCmdCreate

pkg/cmd/label/create_test.go:18–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestNewCmdCreate(t *testing.T) {
19 tests := []struct {
20 name string
21 input string
22 output createOptions
23 wantErr bool
24 errMsg string
25 }{
26 {
27 name: "no argument",
28 input: "",
29 wantErr: true,
30 errMsg: "cannot create label: name argument required",
31 },
32 {
33 name: "name argument",
34 input: "test",
35 output: createOptions{Name: "test"},
36 },
37 {
38 name: "description flag",
39 input: "test --description 'some description'",
40 output: createOptions{Name: "test", Description: "some description"},
41 },
42 {
43 name: "color flag",
44 input: "test --color FFFFFF",
45 output: createOptions{Name: "test", Color: "FFFFFF"},
46 },
47 {
48 name: "color flag with pound sign",
49 input: "test --color '#AAAAAA'",
50 output: createOptions{Name: "test", Color: "AAAAAA"},
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 argv, err := shlex.Split(tt.input)
61 assert.NoError(t, err)
62 var gotOpts *createOptions
63 cmd := newCmdCreate(f, func(opts *createOptions) error {
64 gotOpts = opts
65 return nil
66 })
67 cmd.SetArgs(argv)
68 cmd.SetIn(&bytes.Buffer{})
69 cmd.SetOut(&bytes.Buffer{})
70 cmd.SetErr(&bytes.Buffer{})
71
72 _, err = cmd.ExecuteC()
73 if tt.wantErr {
74 assert.EqualError(t, err, tt.errMsg)
75 return

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…