Break the fs package up into smaller parts.
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.
This commit is contained in:
parent
92624bbbf1
commit
11da2a6c9b
183 changed files with 5749 additions and 5063 deletions
42
lib/readers/readfill_test.go
Normal file
42
lib/readers/readfill_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue