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

Function TestSubscriptionResponseBody

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

Source from the content-addressed store, hash-verified

354}
355
356func TestSubscriptionResponseBody(t *testing.T) {
357 calls := map[string]struct {
358 method, path string
359 call func(EventClient) error
360 }{
361 "create": {"POST", "event-subscriptions", func(c EventClient) error {
362 _, _, err := c.CreateSubscription(context.Background(), "https://github.com/OWNER/REPO/pull/1", []string{"test.a"})
363 return err
364 }},
365 }
366 for name, c := range calls {
367 t.Run(name+" with a body cut short fails like a request in transit", func(t *testing.T) {
368 client, reg := newTestClient(t, "github.com")
369 reg.Register(httpmock.REST(c.method, c.path), func(req *http.Request) (*http.Response, error) {
370 return &http.Response{
371 StatusCode: http.StatusOK, Request: req,
372 Body: io.NopCloser(io.MultiReader(strings.NewReader(`{"id": "sub`), iotest.ErrReader(io.ErrUnexpectedEOF))),
373 }, nil
374 })
375
376 err := c.call(client)
377
378 _, ok := errors.AsType[*url.Error](err)
379 assert.True(t, ok, "got %v", err)
380 assert.ErrorIs(t, err, io.ErrUnexpectedEOF)
381 })
382 t.Run(name+" with a body that is not a subscription fails to decode", func(t *testing.T) {
383 client, reg := newTestClient(t, "github.com")
384 reg.Register(httpmock.REST(c.method, c.path), httpmock.StringResponse(`{"id": "sub`))
385
386 err := c.call(client)
387
388 require.ErrorContains(t, err, "failed to decode response")
389 _, ok := errors.AsType[*url.Error](err)
390 assert.False(t, ok)
391 })
392 }
393}
394
395func TestOpenStream(t *testing.T) {
396 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