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

Function Test_deleteRun

pkg/cmd/gpg-key/delete/delete_test.go:154–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func Test_deleteRun(t *testing.T) {
155 keysResp := "[{\"id\":123,\"key_id\":\"ABC123\"}]"
156 tests := []struct {
157 name string
158 tty bool
159 opts DeleteOptions
160 httpStubs func(*httpmock.Registry)
161 prompterStubs func(*prompter.PrompterMock)
162 wantStdout string
163 wantErr bool
164 wantErrMsg string
165 }{
166 {
167 name: "delete tty",
168 tty: true,
169 opts: DeleteOptions{KeyID: "ABC123", Confirmed: false},
170 prompterStubs: func(pm *prompter.PrompterMock) {
171 pm.ConfirmDeletionFunc = func(_ string) error {
172 return nil
173 }
174 },
175 httpStubs: func(reg *httpmock.Registry) {
176 reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp))
177 reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, ""))
178 },
179 wantStdout: "✓ GPG key ABC123 deleted from your account\n",
180 },
181 {
182 name: "delete with confirm flag tty",
183 tty: true,
184 opts: DeleteOptions{KeyID: "ABC123", Confirmed: true},
185 httpStubs: func(reg *httpmock.Registry) {
186 reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp))
187 reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, ""))
188 },
189 wantStdout: "✓ GPG key ABC123 deleted from your account\n",
190 },
191 {
192 name: "not found tty",
193 tty: true,
194 opts: DeleteOptions{KeyID: "ABC123", Confirmed: true},
195 httpStubs: func(reg *httpmock.Registry) {
196 reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, "[]"))
197 },
198 wantErr: true,
199 wantErrMsg: "unable to delete GPG key ABC123: either the GPG key is not found or it is not owned by you",
200 },
201 {
202 name: "delete no tty",
203 opts: DeleteOptions{KeyID: "ABC123", Confirmed: true},
204 httpStubs: func(reg *httpmock.Registry) {
205 reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp))
206 reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, ""))
207 },
208 wantStdout: "",
209 },
210 {
211 name: "not found no tty",

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
JSONErrorResponseFunction · 0.92
NewMockConfigFunction · 0.92
TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
deleteRunFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected