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

Function Test_deleteRun

pkg/cmd/ssh-key/delete/delete_test.go:111–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func Test_deleteRun(t *testing.T) {
112 keyResp := "{\"title\":\"My Key\"}"
113 tests := []struct {
114 name string
115 tty bool
116 opts DeleteOptions
117 httpStubs func(*httpmock.Registry)
118 prompterStubs func(*prompter.PrompterMock)
119 wantStdout string
120 wantErr bool
121 wantErrMsg string
122 }{
123 {
124 name: "delete tty",
125 tty: true,
126 opts: DeleteOptions{KeyID: "123"},
127 prompterStubs: func(pm *prompter.PrompterMock) {
128 pm.ConfirmDeletionFunc = func(_ string) error {
129 return nil
130 }
131 },
132 httpStubs: func(reg *httpmock.Registry) {
133 reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp))
134 reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, ""))
135 },
136 wantStdout: "✓ SSH key \"My Key\" (123) deleted from your account\n",
137 },
138 {
139 name: "delete with confirm flag tty",
140 tty: true,
141 opts: DeleteOptions{KeyID: "123", Confirmed: true},
142 httpStubs: func(reg *httpmock.Registry) {
143 reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp))
144 reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, ""))
145 },
146 wantStdout: "✓ SSH key \"My Key\" (123) deleted from your account\n",
147 },
148 {
149 name: "not found tty",
150 tty: true,
151 opts: DeleteOptions{KeyID: "123"},
152 httpStubs: func(reg *httpmock.Registry) {
153 reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(404, ""))
154 },
155 wantErr: true,
156 wantErrMsg: "HTTP 404 (https://api.github.com/user/keys/123)",
157 },
158 {
159 name: "delete no tty",
160 opts: DeleteOptions{KeyID: "123", Confirmed: true},
161 httpStubs: func(reg *httpmock.Registry) {
162 reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp))
163 reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, ""))
164 },
165 wantStdout: "",
166 },
167 {
168 name: "not found no tty",

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected