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)
| 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. |
| 39 | func 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 | } |
nothing calls this directly
no test coverage detected