Add skipped test for overwriting existing file in FileHandleWriter

This commit is contained in:
Junjie Qian 2017-05-12 10:36:07 -07:00 коммит произвёл Junjie Qian
Родитель 6ed81c7fc8
Коммит f184a3b20d
1 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -42,3 +42,39 @@ func TestWriteFile(t *testing.T) {
err = writeHandle.Write(h.(*FileHandle), nil, &fuse.WriteRequest{Data: []byte("hello world"), Offset: int64(11)}, &fuse.WriteResponse{})
assert.Equal(t, err, errors.New("Too large file"))
}
func TestFlushFile(t *testing.T) {
t.Skip("Cannot mock hdfsreader for overwiting file")
mockCtrl := gomock.NewController(t)
mockClock := &MockClock{}
hdfsAccessor := NewMockHdfsAccessor(mockCtrl)
fileName := "/testWriteFile_2"
fs, _ := NewFileSystem(hdfsAccessor, "/tmp/x", []string{"*"}, false, NewDefaultRetryPolicy(mockClock), mockClock)
hdfswriter := NewMockHdfsWriter(mockCtrl)
hdfsAccessor.EXPECT().Remove(fileName).Return(nil)
hdfsAccessor.EXPECT().CreateFile(fileName, os.FileMode(0757)).Return(hdfswriter, nil)
hdfswriter.EXPECT().Close().Return(nil)
root, _ := fs.Root()
_, h, _ := root.(*Dir).Create(nil, &fuse.CreateRequest{Name: fileName, Mode: os.FileMode(0757)}, &fuse.CreateResponse{})
// Test for newfilehandlewriter with existing file
hdfsAccessor.EXPECT().CreateFile(fileName, os.FileMode(0757)).Return(hdfswriter, nil)
hdfswriter.EXPECT().Close().Return(nil)
hdfsAccessor.EXPECT().StatFs().Return(FsInfo{capacity: uint64(100), used: uint64(20), remaining: uint64(80)}, nil)
hdfsAccessor.EXPECT().Stat("/testWriteFile_2").Return(Attrs{Name: "testWriteFile_2"}, nil)
// BUG: cannot mock the returned hdfsreader here
hdfsAccessor.EXPECT().OpenRead("/testWriteFile_2").Return(nil, nil)
writeHandle, err := NewFileHandleWriter(h.(*FileHandle), false)
assert.Nil(t, err)
// Test for flush
_ = writeHandle.Write(h.(*FileHandle), nil, &fuse.WriteRequest{Data: []byte("hello world"), Offset: int64(11)}, &fuse.WriteResponse{})
err = writeHandle.Flush()
assert.Nil(t, err)
err = writeHandle.Close()
assert.Nil(t, err)
}