MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdCreate

Function TestNewCmdCreate

pkg/cmd/project/create/create_test.go:14–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestNewCmdCreate(t *testing.T) {
15 tests := []struct {
16 name string
17 cli string
18 wants createOpts
19 wantsErr bool
20 wantsErrMsg string
21 wantsExporter bool
22 }{
23 {
24 name: "title",
25 cli: "--title t",
26 wants: createOpts{
27 title: "t",
28 },
29 },
30 {
31 name: "owner",
32 cli: "--title t --owner monalisa",
33 wants: createOpts{
34 owner: "monalisa",
35 title: "t",
36 },
37 },
38 {
39 name: "json",
40 cli: "--title t --format json",
41 wants: createOpts{
42 title: "t",
43 },
44 wantsExporter: true,
45 },
46 }
47
48 t.Setenv("GH_TOKEN", "auth-token")
49
50 for _, tt := range tests {
51 t.Run(tt.name, func(t *testing.T) {
52 ios, _, _, _ := iostreams.Test()
53 f := &cmdutil.Factory{
54 IOStreams: ios,
55 }
56
57 argv, err := shlex.Split(tt.cli)
58 assert.NoError(t, err)
59
60 var gotOpts createOpts
61 cmd := NewCmdCreate(f, func(config createConfig) error {
62 gotOpts = config.opts
63 return nil
64 })
65
66 cmd.SetArgs(argv)
67 _, err = cmd.ExecuteC()
68 if tt.wantsErr {
69 assert.Error(t, err)
70 assert.Equal(t, tt.wantsErrMsg, err.Error())
71 return

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
EqualMethod · 0.80
NewCmdCreateFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected