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

Function TestSSHKeyUploadHTTPError

pkg/cmd/ssh-key/add/add_test.go:156–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func TestSSHKeyUploadHTTPError(t *testing.T) {
157 reg := &httpmock.Registry{}
158 defer reg.Verify(t)
159 reg.Register(
160 httpmock.REST("GET", "user/keys"),
161 httpmock.StringResponse("[]"),
162 )
163 reg.Register(
164 httpmock.REST("POST", "user/keys"),
165 httpmock.StatusStringResponse(http.StatusUnprocessableEntity, `{"message":"Validation Failed"}`),
166 )
167
168 uploaded, err := SSHKeyUpload(
169 &http.Client{Transport: reg},
170 "github.com",
171 strings.NewReader("ssh-ed25519 asdf"),
172 "",
173 )
174
175 assert.False(t, uploaded)
176 var httpErr api.HTTPError
177 require.ErrorAs(t, err, &httpErr)
178 assert.Equal(t, http.StatusUnprocessableEntity, httpErr.StatusCode)
179 assert.Contains(t, err.Error(), "HTTP 422")
180}

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
StatusStringResponseFunction · 0.92
SSHKeyUploadFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected