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

Function TestRESTError

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

Source from the content-addressed store, hash-verified

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

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