MCPcopy Create free account
hub / github.com/cli/cli / TestSubscriptionResponseBody

Function TestSubscriptionResponseBody

pkg/cmd/event/client/client_test.go:392–429  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

390}
391
392func 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
431func TestOpenStream(t *testing.T) {
432 streamResponse := func(contentType string) httpmock.Responder {

Callers

nothing calls this directly

Calls 6

RESTFunction · 0.92
StringResponseFunction · 0.92
newTestClientFunction · 0.70
CreateSubscriptionMethod · 0.65
RunMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected