(t *testing.T)
| 110 | } |
| 111 | |
| 112 | func 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 | |
| 141 | func TestHandleHTTPError_GraphQL502(t *testing.T) { |
| 142 | req, err := http.NewRequest("GET", "https://api.github.com/user", nil) |
nothing calls this directly
no test coverage detected