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

Function TestNewCmdCreate

pkg/cmd/event/subscription/create/create_test.go:21–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19const resource = "https://github.com/OWNER/REPO/pull/1"
20
21func TestNewCmdCreate(t *testing.T) {
22 tests := []struct {
23 name string
24 args string
25 wantEvents []string
26 wantErr string
27 }{
28 {
29 name: "resource and events",
30 args: "--resource " + resource + " --event test.a,test.b",
31 wantEvents: []string{"test.a", "test.b"},
32 },
33 {
34 name: "missing resource",
35 args: "--event test.a",
36 wantErr: "`--resource` is required",
37 },
38 {
39 name: "missing events",
40 args: "--resource " + resource,
41 wantErr: "`--event` is required",
42 },
43 }
44
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 ios, _, _, _ := iostreams.Test()
48 var gotOpts *CreateOptions
49 cmd := NewCmdCreate(&cmdutil.Factory{IOStreams: ios}, func(opts *CreateOptions) error {
50 gotOpts = opts
51 return nil
52 })
53 args, err := shlex.Split(tt.args)
54 require.NoError(t, err)
55 cmd.SetArgs(args)
56 cmd.SetOut(&bytes.Buffer{})
57 cmd.SetErr(&bytes.Buffer{})
58
59 _, err = cmd.ExecuteC()
60
61 if tt.wantErr != "" {
62 require.ErrorContains(t, err, tt.wantErr)
63 return
64 }
65 require.NoError(t, err)
66 assert.Equal(t, resource, gotOpts.Resource)
67 assert.Equal(t, tt.wantEvents, gotOpts.Events)
68 })
69 }
70}
71
72func TestCreateRun(t *testing.T) {
73 now := time.Date(2026, 1, 2, 3, 0, 0, 0, time.UTC)

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected