rclone/lib/readers/noclose_test.go
Nick Craig-Wood e43b5ce5e5 Remove github.com/pkg/errors and replace with std library version
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.
2021-11-07 11:53:30 +00:00

44 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)
}