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

Function TestRESTWithNextError

api/client_test.go:142–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

140}
141
142func TestRESTWithNextError(t *testing.T) {
143 reg := &httpmock.Registry{}
144 defer reg.Verify(t)
145 client := newTestClient(reg)
146
147 reg.Register(httpmock.MatchAny, func(req *http.Request) (*http.Response, error) {
148 return &http.Response{
149 Request: req,
150 StatusCode: http.StatusNotFound,
151 Body: io.NopCloser(bytes.NewBufferString(`{"message": "Not Found"}`)),
152 Header: http.Header{
153 "Content-Type": {"application/json"},
154 "X-Accepted-Oauth-Scopes": {"repo"},
155 "X-Oauth-Scopes": {"read:user"},
156 },
157 }, nil
158 })
159
160 _, err := client.RESTWithNext("github.com", http.MethodGet, "repos/owner/repo/items", nil, nil)
161
162 var httpErr HTTPError
163 require.ErrorAs(t, err, &httpErr)
164 assert.Equal(t, http.StatusNotFound, httpErr.StatusCode)
165 assert.Contains(t, err.Error(), "HTTP 404")
166 assert.Equal(t, `This API operation needs the "repo" scope. To request it, run: gh auth refresh -h github.com -s repo`, httpErr.ScopesSuggestion())
167}
168
169func TestRESTAndRESTWithNextErrorTypeParity(t *testing.T) {
170 reg := &httpmock.Registry{}

Callers

nothing calls this directly

Calls 8

VerifyMethod · 0.95
RegisterMethod · 0.95
ScopesSuggestionMethod · 0.95
newTestClientFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
RESTWithNextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected