MCPcopy
hub / github.com/cli/cli / Test_deleteRun

Function Test_deleteRun

pkg/cmd/gist/delete/delete_test.go:121–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func Test_deleteRun(t *testing.T) {
122 tests := []struct {
123 name string
124 opts *DeleteOptions
125 cancel bool
126 httpStubs func(*httpmock.Registry)
127 mockPromptGists bool
128 noGists bool
129 wantErr bool
130 wantStdout string
131 wantStderr string
132 }{
133 {
134 name: "successfully delete",
135 opts: &DeleteOptions{
136 Selector: "1234",
137 },
138 httpStubs: func(reg *httpmock.Registry) {
139 reg.Register(httpmock.REST("GET", "gists/1234"),
140 httpmock.JSONResponse(shared.Gist{ID: "1234", Files: map[string]*shared.GistFile{"cool.txt": {Filename: "cool.txt"}}}))
141 reg.Register(httpmock.REST("DELETE", "gists/1234"),
142 httpmock.StatusStringResponse(200, "{}"))
143 },
144 wantStdout: "✓ Gist \"cool.txt\" deleted\n",
145 },
146 {
147 name: "successfully delete with prompt",
148 opts: &DeleteOptions{
149 Selector: "",
150 },
151 httpStubs: func(reg *httpmock.Registry) {
152 reg.Register(httpmock.REST("DELETE", "gists/1234"),
153 httpmock.StatusStringResponse(200, "{}"))
154 },
155 mockPromptGists: true,
156 wantStdout: "✓ Gist \"cool.txt\" deleted\n",
157 },
158 {
159 name: "successfully delete with --yes",
160 opts: &DeleteOptions{
161 Selector: "1234",
162 Confirmed: true,
163 },
164 httpStubs: func(reg *httpmock.Registry) {
165 reg.Register(httpmock.REST("GET", "gists/1234"),
166 httpmock.JSONResponse(shared.Gist{ID: "1234", Files: map[string]*shared.GistFile{"cool.txt": {Filename: "cool.txt"}}}))
167 reg.Register(httpmock.REST("DELETE", "gists/1234"),
168 httpmock.StatusStringResponse(200, "{}"))
169 },
170 wantStdout: "✓ Gist \"cool.txt\" deleted\n",
171 },
172 {
173 name: "successfully delete with prompt and --yes",
174 opts: &DeleteOptions{
175 Selector: "",
176 Confirmed: true,
177 },
178 httpStubs: func(reg *httpmock.Registry) {

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
NewMockPrompterFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewBlankConfigFunction · 0.92
TestFunction · 0.92
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80

Tested by

no test coverage detected