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

Function Test_editRelease_bodyReadError

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

Source from the content-addressed store, hash-verified

544}
545
546func Test_editRelease_bodyReadError(t *testing.T) {
547 readErr := errors.New("read: connection reset by peer")
548 reg := &httpmock.Registry{}
549 defer reg.Verify(t)
550 reg.Register(
551 func(req *http.Request) bool {
552 return req.Method == http.MethodPatch &&
553 req.URL.EscapedPath() == "/repos/OWNER/REPO/releases/12345" &&
554 req.URL.Host == "api.github.com"
555 },
556 func(_ *http.Request) (*http.Response, error) {
557 return &http.Response{
558 StatusCode: 200,
559 Body: io.NopCloser(errorReader{err: readErr}),
560 Header: http.Header{},
561 }, nil
562 },
563 )
564
565 httpClient := &http.Client{Transport: reg}
566 release, err := editRelease(httpClient, ghrepo.New("OWNER", "REPO"), 12345, map[string]any{"tag_name": "v1.2.3"})
567
568 require.Error(t, err)
569 assert.ErrorIs(t, err, readErr)
570 assert.Nil(t, release)
571}
572
573// errorReader always returns the given error on Read, used to simulate body read failures.
574type 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