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

Function TestNewCmdDelete

pkg/cmd/variable/delete/delete_test.go:19–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewCmdDelete(t *testing.T) {
20 tests := []struct {
21 name string
22 cli string
23 wants DeleteOptions
24 wantsErr bool
25 }{
26 {
27 name: "no args",
28 wantsErr: true,
29 },
30 {
31 name: "repo",
32 cli: "cool",
33 wants: DeleteOptions{
34 VariableName: "cool",
35 },
36 },
37 {
38 name: "org",
39 cli: "cool --org anOrg",
40 wants: DeleteOptions{
41 VariableName: "cool",
42 OrgName: "anOrg",
43 },
44 },
45 {
46 name: "env",
47 cli: "cool --env anEnv",
48 wants: DeleteOptions{
49 VariableName: "cool",
50 EnvName: "anEnv",
51 },
52 },
53 }
54
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 ios, _, _, _ := iostreams.Test()
58 f := &cmdutil.Factory{
59 IOStreams: ios,
60 }
61
62 argv, err := shlex.Split(tt.cli)
63 assert.NoError(t, err)
64
65 var gotOpts *DeleteOptions
66 cmd := NewCmdDelete(f, func(opts *DeleteOptions) error {
67 gotOpts = opts
68 return nil
69 })
70 cmd.SetArgs(argv)
71 cmd.SetIn(&bytes.Buffer{})
72 cmd.SetOut(&bytes.Buffer{})
73 cmd.SetErr(&bytes.Buffer{})
74
75 _, err = cmd.ExecuteC()
76 if tt.wantsErr {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected