(t *testing.T)
| 390 | } |
| 391 | |
| 392 | func TestSubscriptionResponseBody(t *testing.T) { |
| 393 | calls := map[string]struct { |
| 394 | method, path string |
| 395 | call func(EventClient) error |
| 396 | }{ |
| 397 | "create": {"POST", "event-subscriptions", func(c EventClient) error { |
| 398 | _, _, err := c.CreateSubscription(context.Background(), "https://github.com/OWNER/REPO/pull/1", []string{"test.a"}) |
| 399 | return err |
| 400 | }}, |
| 401 | } |
| 402 | for name, c := range calls { |
| 403 | t.Run(name+" with a body cut short fails like a request in transit", func(t *testing.T) { |
| 404 | client, reg := newTestClient(t, "github.com") |
| 405 | reg.Register(httpmock.REST(c.method, c.path), func(req *http.Request) (*http.Response, error) { |
| 406 | return &http.Response{ |
| 407 | StatusCode: http.StatusOK, Request: req, |
| 408 | Body: io.NopCloser(io.MultiReader(strings.NewReader(`{"id": "sub`), iotest.ErrReader(io.ErrUnexpectedEOF))), |
| 409 | }, nil |
| 410 | }) |
| 411 | |
| 412 | err := c.call(client) |
| 413 | |
| 414 | _, ok := errors.AsType[*url.Error](err) |
| 415 | assert.True(t, ok, "got %v", err) |
| 416 | assert.ErrorIs(t, err, io.ErrUnexpectedEOF) |
| 417 | }) |
| 418 | t.Run(name+" with a body that is not a subscription fails to decode", func(t *testing.T) { |
| 419 | client, reg := newTestClient(t, "github.com") |
| 420 | reg.Register(httpmock.REST(c.method, c.path), httpmock.StringResponse(`{"id": "sub`)) |
| 421 | |
| 422 | err := c.call(client) |
| 423 | |
| 424 | require.ErrorContains(t, err, "failed to decode response") |
| 425 | _, ok := errors.AsType[*url.Error](err) |
| 426 | assert.False(t, ok) |
| 427 | }) |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | func TestOpenStream(t *testing.T) { |
| 432 | streamResponse := func(contentType string) httpmock.Responder { |
nothing calls this directly
no test coverage detected