From 23e9fefd0b7c63ba2427931322a3804be67a2dea Mon Sep 17 00:00:00 2001 From: Niklas Paulicks Date: Mon, 6 Mar 2023 08:35:44 +0100 Subject: [PATCH] Review fixes --- go.sum | 5 +++++ retry_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/go.sum b/go.sum index e930c2d2..7b4eb43e 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,7 @@ golang.org/x/net v0.0.0-20220325170049-de3da57026de h1:pZB1TWnKi+o4bENlbzAgLrEbY4RMYmUIRobMcSmfeYc= +golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/retry_test.go b/retry_test.go index 1475c7ae..d979fbfe 100644 --- a/retry_test.go +++ b/retry_test.go @@ -9,6 +9,8 @@ import ( "context" "encoding/json" "errors" + "fmt" + "io" "net/http" "reflect" "strconv" @@ -735,6 +737,46 @@ func filler(*Response, error) bool { return false } +var seekFailure = fmt.Errorf("failing seek test") + +type failingSeeker struct { + reader *bytes.Reader +} + +func (f failingSeeker) Read(b []byte) (n int, err error) { + return f.reader.Read(b) +} + +func (f failingSeeker) Seek(offset int64, whence int) (int64, error) { + if offset == 0 && whence == io.SeekStart { + return 0, seekFailure + } + + return f.reader.Seek(offset, whence) +} + +func TestResetMultipartReaderSeekStartError(t *testing.T) { + ts := createFilePostServer(t) + defer ts.Close() + + testSeeker := &failingSeeker{ + bytes.NewReader([]byte("test")), + } + + c := dc(). + SetRetryCount(2). + SetTimeout(time.Second * 3). + SetRetryResetReaders(true). + AddRetryAfterErrorCondition() + + resp, err := c.R(). + SetFileReader("name", "filename", testSeeker). + Post(ts.URL + "/set-reset-multipart-readers-test") + + assertEqual(t, 500, resp.StatusCode()) + assertEqual(t, err.Error(), seekFailure.Error()) +} + func TestResetMultipartReaders(t *testing.T) { ts := createFilePostServer(t) defer ts.Close()