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

Function TestRequestErrorPreservesScopesSuggestion

api/request_test.go:186–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

184}
185
186func 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.

Callers

nothing calls this directly

Calls 6

VerifyMethod · 0.95
RegisterMethod · 0.95
ScopesSuggestionMethod · 0.95
newTestClientFunction · 0.85
RequestMethod · 0.80
ContainsMethod · 0.80

Tested by

no test coverage detected