diff --git a/vfs/write_test.go b/vfs/write_test.go index 6c607ec08..867326357 100644 --- a/vfs/write_test.go +++ b/vfs/write_test.go @@ -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) +}