Add a test for the EOF behaviour of Read.

This commit is contained in:
Jamie Wilkinson 2015-03-22 11:24:08 +11:00 committed by spf13
parent 139e50e29a
commit 56a1f83590
1 changed files with 27 additions and 0 deletions

27
memfile_test.go Normal file
View File

@ -0,0 +1,27 @@
package afero
import (
"io"
"testing"
)
func TestMemFileRead(t *testing.T) {
f := MemFileCreate("testfile")
f.WriteString("abcd")
f.Seek(0, 0)
b := make([]byte, 8)
n, err := f.Read(b)
if n != 4 {
t.Errorf("didn't read all bytes: %v %v %v", n, err, b)
}
if err != nil {
t.Errorf("err is not nil: %v %v %v", n, err, b)
}
n, err = f.Read(b)
if n != 0 {
t.Errorf("read more bytes: %v %v %v", n, err, b)
}
if err != io.EOF {
t.Errorf("error is not EOF: %v %v %v", n, err, b)
}
}