(t *testing.T)
| 505 | } |
| 506 | |
| 507 | func 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. |
| 535 | type errorReader struct{ err error } |
nothing calls this directly
no test coverage detected