mirror of
https://github.com/rclone/rclone
synced 2024-11-29 07:55:12 +01:00
e43b5ce5e5
This is possible now that we no longer support go1.12 and brings rclone into line with standard practices in the Go world. This also removes errors.New and errors.Errorf from lib/errors and prefers the stdlib errors package over lib/errors.
45 lines
699 B
Go
45 lines
699 B
Go
package readers
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var errRead = errors.New("read error")
|
|
|
|
type readOnly struct{}
|
|
|
|
func (readOnly) Read(p []byte) (n int, err error) {
|
|
return 0, io.EOF
|
|
}
|
|
|
|
type readClose struct{}
|
|
|
|
func (readClose) Read(p []byte) (n int, err error) {
|
|
return 0, errRead
|
|
}
|
|
|
|
func (readClose) Close() (err error) {
|
|
return io.EOF
|
|
}
|
|
|
|
func TestNoCloser(t *testing.T) {
|
|
assert.Equal(t, nil, NoCloser(nil))
|
|
|
|
ro := readOnly{}
|
|
assert.Equal(t, ro, NoCloser(ro))
|
|
|
|
rc := readClose{}
|
|
nc := NoCloser(rc)
|
|
assert.NotEqual(t, nc, rc)
|
|
|
|
_, hasClose := nc.(io.Closer)
|
|
assert.False(t, hasClose)
|
|
|
|
_, err := nc.Read(nil)
|
|
assert.Equal(t, errRead, err)
|
|
}
|