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

Function Test_deleteRun

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
NewBlankConfigFunction · 0.92
TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
deleteRunFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected