mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
11da2a6c9b
The purpose of this is to make it easier to maintain and eventually to allow the rclone backends to be re-used in other projects without having to use the rclone configuration system. The new code layout is documented in CONTRIBUTING.
43 lines
761 B
Go
43 lines
761 B
Go
package readers
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type byteReader struct {
|
|
c byte
|
|
}
|
|
|
|
func (br *byteReader) Read(p []byte) (n int, err error) {
|
|
if br.c == 0 {
|
|
err = io.EOF
|
|
} else if len(p) >= 1 {
|
|
p[0] = br.c
|
|
n = 1
|
|
br.c--
|
|
}
|
|
return
|
|
}
|
|
|
|
func TestReadFill(t *testing.T) {
|
|
buf := []byte{9, 9, 9, 9, 9}
|
|
|
|
n, err := ReadFill(&byteReader{0}, buf)
|
|
assert.Equal(t, io.EOF, err)
|
|
assert.Equal(t, 0, n)
|
|
assert.Equal(t, []byte{9, 9, 9, 9, 9}, buf)
|
|
|
|
n, err = ReadFill(&byteReader{3}, buf)
|
|
assert.Equal(t, io.EOF, err)
|
|
assert.Equal(t, 3, n)
|
|
assert.Equal(t, []byte{3, 2, 1, 9, 9}, buf)
|
|
|
|
n, err = ReadFill(&byteReader{8}, buf)
|
|
assert.Equal(t, nil, err)
|
|
assert.Equal(t, 5, n)
|
|
assert.Equal(t, []byte{8, 7, 6, 5, 4}, buf)
|
|
}
|