mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 00:28:09 +02:00
lib/readers: factor ErrorReader from multiple sources
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/hash"
|
||||
"github.com/rclone/rclone/fstest/mockobject"
|
||||
"github.com/rclone/rclone/lib/readers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -44,23 +45,13 @@ func (o *reOpenTestObject) Open(ctx context.Context, options ...fs.OpenOption) (
|
||||
return nil, errorTestError
|
||||
}
|
||||
// Read N bytes then an error
|
||||
r := io.MultiReader(&io.LimitedReader{R: rc, N: N}, errorReader{errorTestError})
|
||||
r := io.MultiReader(&io.LimitedReader{R: rc, N: N}, readers.ErrorReader{Err: errorTestError})
|
||||
// Wrap with Close in a new readCloser
|
||||
rc = readCloser{Reader: r, Closer: rc}
|
||||
}
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
// Return an error only
|
||||
type errorReader struct {
|
||||
err error
|
||||
}
|
||||
|
||||
// Read returning an error
|
||||
func (er errorReader) Read(p []byte) (n int, err error) {
|
||||
return 0, er.err
|
||||
}
|
||||
|
||||
func TestReOpen(t *testing.T) {
|
||||
for testIndex, testName := range []string{"Seek", "Range"} {
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user