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

Function TestNewCmdDelete

pkg/cmd/run/delete/delete_test.go:21–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestNewCmdDelete(t *testing.T) {
22 tests := []struct {
23 name string
24 cli string
25 tty bool
26 wants DeleteOptions
27 wantsErr bool
28 prompterStubs func(*prompter.PrompterMock)
29 }{
30 {
31 name: "blank tty",
32 tty: true,
33 wants: DeleteOptions{
34 Prompt: true,
35 },
36 },
37 {
38 name: "blank nontty",
39 wantsErr: true,
40 },
41 {
42 name: "with arg",
43 cli: "1234",
44 wants: DeleteOptions{
45 RunID: "1234",
46 },
47 },
48 }
49
50 for _, tt := range tests {
51 t.Run(tt.name, func(t *testing.T) {
52 ios, _, _, _ := iostreams.Test()
53 ios.SetStdinTTY(tt.tty)
54 ios.SetStdoutTTY(tt.tty)
55
56 f := &cmdutil.Factory{
57 IOStreams: ios,
58 }
59
60 argv, err := shlex.Split(tt.cli)
61 assert.NoError(t, err)
62
63 var gotOpts *DeleteOptions
64 cmd := NewCmdDelete(f, func(opts *DeleteOptions) error {
65 gotOpts = opts
66 return nil
67 })
68
69 cmd.SetArgs(argv)
70 cmd.SetIn(&bytes.Buffer{})
71 cmd.SetOut(io.Discard)
72 cmd.SetErr(io.Discard)
73
74 _, err = cmd.ExecuteC()
75 if tt.wantsErr {
76 assert.Error(t, err)
77 return
78 }

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
NewCmdDeleteFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected