From 96c189ab5091baf3bffeaaaeed7beeb407f9cae3 Mon Sep 17 00:00:00 2001 From: Jamie Wilkinson Date: Sun, 22 Mar 2015 11:24:08 +1100 Subject: [PATCH] Add a test for the EOF behaviour of Read. --- memfile_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 memfile_test.go diff --git a/memfile_test.go b/memfile_test.go new file mode 100644 index 0000000..b77ae8e --- /dev/null +++ b/memfile_test.go @@ -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) + } +}