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

Function Test_editRelease_bodyReadError

pkg/cmd/release/edit/edit_test.go:507–532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

505}
506
507func Test_editRelease_bodyReadError(t *testing.T) {
508 readErr := errors.New("read: connection reset by peer")
509 reg := &httpmock.Registry{}
510 defer reg.Verify(t)
511 reg.Register(
512 func(req *http.Request) bool {
513 return req.Method == http.MethodPatch &&
514 req.URL.EscapedPath() == "/repos/OWNER/REPO/releases/12345" &&
515 req.URL.Host == "api.github.com"
516 },
517 func(_ *http.Request) (*http.Response, error) {
518 return &http.Response{
519 StatusCode: 200,
520 Body: io.NopCloser(errorReader{err: readErr}),
521 Header: http.Header{},
522 }, nil
523 },
524 )
525
526 httpClient := &http.Client{Transport: reg}
527 release, err := editRelease(httpClient, ghrepo.New("OWNER", "REPO"), 12345, map[string]any{"tag_name": "v1.2.3"})
528
529 require.Error(t, err)
530 assert.ErrorIs(t, err, readErr)
531 assert.Nil(t, release)
532}
533
534// errorReader always returns the given error on Read, used to simulate body read failures.
535type errorReader struct{ err error }

Callers

nothing calls this directly

Calls 5

VerifyMethod · 0.95
RegisterMethod · 0.95
NewFunction · 0.92
editReleaseFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected