Skip to content

Commit 6d7a21f

Browse files
committed
test: cover stopMultipart nil receiver and isMultipartStopError branches
Bring patch coverage on the new helpers to 100% per maintainer request: - stopMultipart: add nil-receiver guard test - isMultipartStopError: table test covering nil, sentinel errors, wrapped errors, and string-fallback matching
1 parent 6480241 commit 6d7a21f

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

middleware_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,3 +1366,12 @@ func TestMultipartReturnsAfterEarlyResponse(t *testing.T) {
13661366
t.Fatal("multipart request did not return after the transport responded")
13671367
}
13681368
}
1369+
1370+
func TestStopMultipartNilReceiver(t *testing.T) {
1371+
// nil receiver must be a no-op and must not panic.
1372+
var r *Request
1373+
r.stopMultipart()
1374+
1375+
// A request with no cancel func / pipe writer / fields must also be safe.
1376+
(&Request{}).stopMultipart()
1377+
}

util_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package resty
77

88
import (
99
"bytes"
10+
"context"
1011
"errors"
1112
"fmt"
1213
"io"
@@ -408,3 +409,25 @@ func TestFormatAnyToString(t *testing.T) {
408409
})
409410
}
410411
}
412+
413+
func TestIsMultipartStopError(t *testing.T) {
414+
for _, tc := range []struct {
415+
name string
416+
err error
417+
expect bool
418+
}{
419+
{"nil", nil, false},
420+
{"closed pipe", io.ErrClosedPipe, true},
421+
{"context canceled", context.Canceled, true},
422+
{"deadline exceeded", context.DeadlineExceeded, true},
423+
{"wrapped closed pipe", fmt.Errorf("write: %w", io.ErrClosedPipe), true},
424+
{"closed pipe string", errors.New("io: read/write on closed pipe"), true},
425+
{"context canceled string", errors.New("context canceled"), true},
426+
{"unrelated", errors.New("boom"), false},
427+
} {
428+
t.Run(tc.name, func(t *testing.T) {
429+
assertEqual(t, tc.expect, isMultipartStopError(tc.err))
430+
})
431+
}
432+
}
433+

0 commit comments

Comments
 (0)