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

Function TestNewCmdDelete

pkg/cmd/event/subscription/delete/delete_test.go:18–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestNewCmdDelete(t *testing.T) {
19 tests := []struct {
20 name string
21 args string
22 wantID string
23 wantErr string
24 }{
25 {
26 name: "id",
27 args: "sub_1",
28 wantID: "sub_1",
29 },
30 {
31 name: "no id",
32 wantErr: "subscription ID required",
33 },
34 {
35 name: "more than one id",
36 args: "sub_1 sub_2",
37 wantErr: "too many arguments",
38 },
39 }
40
41 for _, tt := range tests {
42 t.Run(tt.name, func(t *testing.T) {
43 ios, _, _, _ := iostreams.Test()
44 var gotOpts *DeleteOptions
45 cmd := NewCmdDelete(&cmdutil.Factory{IOStreams: ios}, func(opts *DeleteOptions) error {
46 gotOpts = opts
47 return nil
48 })
49 args, err := shlex.Split(tt.args)
50 require.NoError(t, err)
51 cmd.SetArgs(args)
52 cmd.SetOut(&bytes.Buffer{})
53 cmd.SetErr(&bytes.Buffer{})
54
55 _, err = cmd.ExecuteC()
56
57 if tt.wantErr != "" {
58 require.ErrorContains(t, err, tt.wantErr)
59 assert.Nil(t, gotOpts)
60 return
61 }
62 require.NoError(t, err)
63 assert.Equal(t, tt.wantID, gotOpts.ID)
64 })
65 }
66}
67
68func TestDeleteRun(t *testing.T) {
69 tests := []struct {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected