| 229 | } |
| 230 | |
| 231 | func TestGetSSHKeyHTTPError(t *testing.T) { |
| 232 | reg := &httpmock.Registry{} |
| 233 | defer reg.Verify(t) |
| 234 | reg.Register( |
| 235 | httpmock.REST("GET", "user/keys/1234"), |
| 236 | httpmock.StatusStringResponse(http.StatusNotFound, `{"message":"Not Found"}`), |
| 237 | ) |
| 238 | |
| 239 | key, err := getSSHKey(&http.Client{Transport: reg}, "github.com", "1234") |
| 240 | |
| 241 | assert.Nil(t, key) |
| 242 | var httpErr api.HTTPError |
| 243 | require.ErrorAs(t, err, &httpErr) |
| 244 | assert.Equal(t, http.StatusNotFound, httpErr.StatusCode) |
| 245 | assert.Contains(t, err.Error(), "HTTP 404") |
| 246 | } |