(t *testing.T)
| 111 | } |
| 112 | |
| 113 | func 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 | |
| 142 | func TestRESTWithNextError(t *testing.T) { |
| 143 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected