(t *testing.T)
| 544 | } |
| 545 | |
| 546 | func 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. |
| 574 | type errorReader struct{ err error } |
nothing calls this directly
no test coverage detected