(t *testing.T)
| 154 | } |
| 155 | |
| 156 | func 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 | } |
nothing calls this directly
no test coverage detected