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

Function TestGetCommitsHTTPError

pkg/cmd/repo/garden/http_test.go:39–55  ·  view source on GitHub ↗

TestGetCommitsHTTPError pins the error returned on a non-2xx response. This site used to return a bare "api call failed", and now surfaces the API's own message via api.HTTPError.

(t *testing.T)

Source from the content-addressed store, hash-verified

37// TestGetCommitsHTTPError pins the error returned on a non-2xx response. This site used to
38// return a bare "api call failed", and now surfaces the API's own message via api.HTTPError.
39func TestGetCommitsHTTPError(t *testing.T) {
40 reg := &httpmock.Registry{}
41 defer reg.Verify(t)
42
43 reg.Register(
44 httpmock.REST("GET", "repos/OWNER/REPO/commits"),
45 httpmock.StatusJSONResponse(404, map[string]string{"message": "Not Found"}),
46 )
47
48 _, err := getCommits(&http.Client{Transport: reg}, ghrepo.New("OWNER", "REPO"), 10)
49 require.Error(t, err)
50
51 var httpErr api.HTTPError
52 require.ErrorAs(t, err, &httpErr)
53 assert.Equal(t, 404, httpErr.StatusCode)
54 assert.Equal(t, "Not Found", httpErr.Message)
55}

Callers

nothing calls this directly

Calls 8

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StatusJSONResponseFunction · 0.92
NewFunction · 0.92
getCommitsFunction · 0.85
EqualMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected