(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestRequestErrorPreservesScopesSuggestion(t *testing.T) { |
| 187 | reg := &httpmock.Registry{} |
| 188 | defer reg.Verify(t) |
| 189 | client := newTestClient(reg) |
| 190 | |
| 191 | reg.Register(httpmock.MatchAny, func(req *http.Request) (*http.Response, error) { |
| 192 | return &http.Response{ |
| 193 | Request: req, |
| 194 | StatusCode: 404, |
| 195 | Body: io.NopCloser(bytes.NewBufferString(`{"message": "Not Found"}`)), |
| 196 | Header: map[string][]string{ |
| 197 | "Content-Type": {"application/json; charset=utf-8"}, |
| 198 | "X-Accepted-Oauth-Scopes": {"delete_repo"}, |
| 199 | "X-Oauth-Scopes": {"repo"}, |
| 200 | }, |
| 201 | }, nil |
| 202 | }) |
| 203 | |
| 204 | _, err := client.Request("github.com", http.MethodDelete, "repos/OWNER/REPO", nil) |
| 205 | |
| 206 | var httpErr HTTPError |
| 207 | require.ErrorAs(t, err, &httpErr) |
| 208 | assert.Contains(t, httpErr.ScopesSuggestion(), "delete_repo") |
| 209 | } |
| 210 | |
| 211 | // Call sites used to mutate the response with EndpointNeedsScopes before converting it to an error. |
| 212 | // Request converts internally, so WithEndpointScopes has to reproduce that suggestion. |
nothing calls this directly
no test coverage detected