(t *testing.T)
| 298 | } |
| 299 | |
| 300 | func TestDoRequest(t *testing.T) { |
| 301 | reg := &httpmock.Registry{} |
| 302 | defer reg.Verify(t) |
| 303 | client := newTestClient(reg) |
| 304 | |
| 305 | reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(201, `{"id": 1}`)) |
| 306 | |
| 307 | // Fields such as ContentLength are the reason DoRequest exists, so assert one survives. |
| 308 | req, err := http.NewRequest(http.MethodPost, "https://uploads.github.com/assets", strings.NewReader("longer-than-assigned-content-length")) |
| 309 | require.NoError(t, err) |
| 310 | req.ContentLength = 1 |
| 311 | |
| 312 | resp, err := client.DoRequest(req) |
| 313 | require.NoError(t, err) |
| 314 | defer resp.Body.Close() |
| 315 | |
| 316 | assert.Equal(t, 201, resp.StatusCode) |
| 317 | assert.Equal(t, "uploads.github.com", reg.Requests[0].URL.Hostname()) |
| 318 | assert.Equal(t, int64(1), reg.Requests[0].ContentLength) |
| 319 | |
| 320 | body, err := io.ReadAll(resp.Body) |
| 321 | require.NoError(t, err) |
| 322 | assert.Equal(t, `{"id": 1}`, string(body)) |
| 323 | } |
| 324 | |
| 325 | func TestDoRequestError(t *testing.T) { |
| 326 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected