vfs: add test for 0 length files read in the way mount does

This commit is contained in:
Nick Craig-Wood 2019-08-03 18:24:12 +01:00
parent 0be14120e4
commit 0386d22cc9

View File

@ -2,6 +2,7 @@ package vfs
import (
"context"
"io"
"os"
"sync"
"testing"
@ -286,3 +287,32 @@ func TestWriteFileModTimeWithOpenWriters(t *testing.T) {
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
}
}
func TestFileZeroLength(t *testing.T) {
r := fstest.NewRun(t)
defer r.Finalise()
vfs, fh := writeHandleCreate(t, r)
// Close the file without writing to it
err := fh.Close()
if errors.Cause(err) == fs.ErrorCantUploadEmptyFiles {
t.Logf("skipping test: %v", err)
return
}
assert.NoError(t, err)
// read the 0 length file back in using ReadAt into a buffer
// this simulates what mount does
rd, err := vfs.OpenFile("file1", os.O_RDONLY, 0)
require.NoError(t, err)
buf := make([]byte, 1024)
n, err := rd.ReadAt(buf, 0)
if err != io.EOF {
assert.NoError(t, err)
}
assert.Equal(t, 0, n)
err = rd.Close()
assert.NoError(t, err)
}