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

Function TestNewCmdDelete

pkg/cmd/alias/delete/delete_test.go:17–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestNewCmdDelete(t *testing.T) {
18 tests := []struct {
19 name string
20 input string
21 output DeleteOptions
22 wantErr bool
23 errMsg string
24 }{
25 {
26 name: "no arguments",
27 input: "",
28 wantErr: true,
29 errMsg: "specify an alias to delete or `--all`",
30 },
31 {
32 name: "specified alias",
33 input: "co",
34 output: DeleteOptions{
35 Name: "co",
36 },
37 },
38 {
39 name: "all flag",
40 input: "--all",
41 output: DeleteOptions{
42 All: true,
43 },
44 },
45 {
46 name: "specified alias and all flag",
47 input: "co --all",
48 wantErr: true,
49 errMsg: "cannot use `--all` with alias name",
50 },
51 {
52 name: "too many arguments",
53 input: "il co",
54 wantErr: true,
55 errMsg: "accepts at most 1 arg(s), received 2",
56 },
57 }
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 ios, _, _, _ := iostreams.Test()
61 f := &cmdutil.Factory{
62 IOStreams: ios,
63 }
64 argv, err := shlex.Split(tt.input)
65 assert.NoError(t, err)
66 var gotOpts *DeleteOptions
67 cmd := NewCmdDelete(f, func(opts *DeleteOptions) error {
68 gotOpts = opts
69 return nil
70 })
71 cmd.SetArgs(argv)
72 cmd.SetIn(&bytes.Buffer{})
73 cmd.SetOut(io.Discard)
74 cmd.SetErr(io.Discard)

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