mirror of https://github.com/spf13/afero.git
Fixes #352.
Add tests: - ``*mem.File` implementation of `io.ReaderAt` must return non-nil error when reading less than length of give slice. - `MemMapFs` must pass `fstest.TestFS` tests for non-empty files. Fixes the bug.
This commit is contained in:
parent
100c9a6d7b
commit
24ef172f2b
10
iofs_test.go
10
iofs_test.go
|
@ -29,7 +29,15 @@ func TestIOFS(t *testing.T) {
|
|||
t.Fatal("OpenFile (O_CREATE) failed:", err)
|
||||
}
|
||||
|
||||
f.Close()
|
||||
_, err = f.WriteString("a")
|
||||
if err != nil {
|
||||
t.Fatal("WriteString failed:", err)
|
||||
}
|
||||
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
t.Fatal("Close failed:", err)
|
||||
}
|
||||
|
||||
if err := fstest.TestFS(NewIOFS(mmfs), "dir1/dir2/test.txt"); err != nil {
|
||||
t.Error(err)
|
||||
|
|
|
@ -210,6 +210,11 @@ func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
|
|||
atomic.StoreInt64(&f.at, off)
|
||||
n, err = f.Read(b)
|
||||
atomic.StoreInt64(&f.at, prev)
|
||||
if int64(n) == int64(len(f.fileData.data))-off {
|
||||
if n < len(b) {
|
||||
err = io.EOF
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ func TestFileReadAtSeekOffset(t *testing.T) {
|
|||
t.Fatal("expected 0")
|
||||
}
|
||||
|
||||
b := make([]byte, 4)
|
||||
b := make([]byte, 4, 5)
|
||||
n, err := f.ReadAt(b, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -244,6 +244,17 @@ func TestFileReadAtSeekOffset(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
|
||||
n, err = f.ReadAt(b[:cap(b)], 0)
|
||||
if err != io.EOF {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 4 {
|
||||
t.Fail()
|
||||
}
|
||||
if string(b) != "TEST" {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
offsetAfterReadAt, err := f.Seek(0, io.SeekCurrent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
Loading…
Reference in New Issue