MCPcopy
hub / github.com/cli/cli / TestRESTError

Function TestRESTError

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

Source from the content-addressed store, hash-verified

110}
111
112func TestRESTError(t *testing.T) {
113 fakehttp := &httpmock.Registry{}
114 client := newTestClient(fakehttp)
115
116 fakehttp.Register(httpmock.MatchAny, func(req *http.Request) (*http.Response, error) {
117 return &http.Response{
118 Request: req,
119 StatusCode: 422,
120 Body: io.NopCloser(bytes.NewBufferString(`{"message": "OH NO"}`)),
121 Header: map[string][]string{
122 "Content-Type": {"application/json; charset=utf-8"},
123 },
124 }, nil
125 })
126
127 var httpErr HTTPError
128 err := client.REST("github.com", "DELETE", "repos/branch", nil, nil)
129 if err == nil || !errors.As(err, &httpErr) {
130 t.Fatalf("got %v", err)
131 }
132
133 if httpErr.StatusCode != 422 {
134 t.Errorf("expected status code 422, got %d", httpErr.StatusCode)
135 }
136 if httpErr.Error() != "HTTP 422: OH NO (https://api.github.com/repos/branch)" {
137 t.Errorf("got %q", httpErr.Error())
138 }
139}
140
141func TestHandleHTTPError_GraphQL502(t *testing.T) {
142 req, err := http.NewRequest("GET", "https://api.github.com/user", nil)

Callers

nothing calls this directly

Calls 5

RegisterMethod · 0.95
newTestClientFunction · 0.85
RESTMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected