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

Function Test_createGist_missingScope

pkg/cmd/gist/create/create_test.go:423–448  ·  view source on GitHub ↗

Test_createGist_missingScope pins the scopes suggestion, which is the reason this call site declares the gist scope rather than relying on what the API reports.

(t *testing.T)

Source from the content-addressed store, hash-verified

421// Test_createGist_missingScope pins the scopes suggestion, which is the reason this call site
422// declares the gist scope rather than relying on what the API reports.
423func Test_createGist_missingScope(t *testing.T) {
424 reg := &httpmock.Registry{}
425 defer reg.Verify(t)
426
427 reg.Register(
428 httpmock.REST("POST", "gists"),
429 func(req *http.Request) (*http.Response, error) {
430 resp, err := httpmock.StatusJSONResponse(404, map[string]string{"message": "Not Found"})(req)
431 if err != nil {
432 return nil, err
433 }
434 resp.Header.Set("X-Oauth-Scopes", "repo")
435 resp.Header.Set("X-Accepted-Oauth-Scopes", "")
436 return resp, nil
437 },
438 )
439
440 _, err := createGist(&http.Client{Transport: reg}, "github.com", "", true, map[string]*shared.GistFile{
441 "file.txt": {Filename: "file.txt", Content: "hello"},
442 })
443 require.Error(t, err)
444
445 var httpErr api.HTTPError
446 require.ErrorAs(t, err, &httpErr)
447 assert.Contains(t, httpErr.ScopesSuggestion(), "gist")
448}

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
ScopesSuggestionMethod · 0.95
RESTFunction · 0.92
StatusJSONResponseFunction · 0.92
createGistFunction · 0.85
ContainsMethod · 0.80
SetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected