2016-07-17 22:03:23 +00:00
|
|
|
// +build linux darwin freebsd
|
|
|
|
|
2017-05-02 21:35:07 +00:00
|
|
|
package mounttest
|
2016-07-17 22:03:23 +00:00
|
|
|
|
|
|
|
import (
|
2017-02-06 21:17:45 +00:00
|
|
|
"io/ioutil"
|
2016-07-17 22:03:23 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
2017-03-23 19:41:21 +00:00
|
|
|
"time"
|
2016-07-17 22:03:23 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDirLs(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.checkDir(t, "")
|
|
|
|
|
|
|
|
run.mkdir(t, "a directory")
|
|
|
|
run.createFile(t, "a file", "hello")
|
|
|
|
|
|
|
|
run.checkDir(t, "a directory/|a file 5")
|
|
|
|
|
|
|
|
run.rmdir(t, "a directory")
|
|
|
|
run.rm(t, "a file")
|
|
|
|
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirCreateAndRemoveDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir/subdir")
|
|
|
|
run.checkDir(t, "dir/|dir/subdir/")
|
|
|
|
|
|
|
|
// Check we can't delete a directory with stuff in
|
|
|
|
err := os.Remove(run.path("dir"))
|
|
|
|
assert.Error(t, err, "file exists")
|
|
|
|
|
|
|
|
// Now delete subdir then dir - should produce no errors
|
|
|
|
run.rmdir(t, "dir/subdir")
|
|
|
|
run.checkDir(t, "dir/")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirCreateAndRemoveFile(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "dir/file", "potato")
|
|
|
|
run.checkDir(t, "dir/|dir/file 6")
|
|
|
|
|
|
|
|
// Check we can't delete a directory with stuff in
|
|
|
|
err := os.Remove(run.path("dir"))
|
|
|
|
assert.Error(t, err, "file exists")
|
|
|
|
|
|
|
|
// Now delete file
|
|
|
|
run.rm(t, "dir/file")
|
|
|
|
|
|
|
|
run.checkDir(t, "dir/")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirRenameFile(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "file", "potato")
|
|
|
|
run.checkDir(t, "dir/|file 6")
|
|
|
|
|
2017-02-06 21:17:45 +00:00
|
|
|
err := os.Rename(run.path("file"), run.path("file2"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
2017-02-06 21:17:45 +00:00
|
|
|
run.checkDir(t, "dir/|file2 6")
|
2016-07-17 22:03:23 +00:00
|
|
|
|
2017-02-06 21:17:45 +00:00
|
|
|
data, err := ioutil.ReadFile(run.path("file2"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "potato", string(data))
|
|
|
|
|
|
|
|
err = os.Rename(run.path("file2"), run.path("dir/file3"))
|
2016-07-17 22:03:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/file3 6")
|
|
|
|
|
2017-02-06 21:17:45 +00:00
|
|
|
data, err = ioutil.ReadFile(run.path("dir/file3"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "potato", string(data))
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.rm(t, "dir/file3")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirRenameEmptyDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir1")
|
|
|
|
run.checkDir(t, "dir/|dir1/")
|
|
|
|
|
|
|
|
err := os.Rename(run.path("dir1"), run.path("dir/dir2"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir2/")
|
|
|
|
|
|
|
|
err = os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir3/")
|
|
|
|
|
|
|
|
run.rmdir(t, "dir/dir3")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirRenameFullDir(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "dir1")
|
|
|
|
run.createFile(t, "dir1/potato.txt", "maris piper")
|
|
|
|
run.checkDir(t, "dir/|dir1/|dir1/potato.txt 11")
|
|
|
|
|
|
|
|
err := os.Rename(run.path("dir1"), run.path("dir/dir2"))
|
2017-02-06 21:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir2/|dir/dir2/potato.txt 11")
|
|
|
|
|
|
|
|
err = os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
run.checkDir(t, "dir/|dir/dir3/|dir/dir3/potato.txt 11")
|
|
|
|
|
|
|
|
run.rm(t, "dir/dir3/potato.txt")
|
|
|
|
run.rmdir(t, "dir/dir3")
|
2016-07-17 22:03:23 +00:00
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
2017-03-23 19:41:21 +00:00
|
|
|
|
|
|
|
func TestDirModTime(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
run.mkdir(t, "dir")
|
|
|
|
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC)
|
|
|
|
err := os.Chtimes(run.path("dir"), mtime, mtime)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
info, err := os.Stat(run.path("dir"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// avoid errors because of timezone differences
|
|
|
|
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
|
|
|
|
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
}
|
2017-05-04 20:49:06 +00:00
|
|
|
|
|
|
|
func TestDirCacheFlush(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
|
|
|
run.checkDir(t, "")
|
|
|
|
|
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.mkdir(t, "otherdir")
|
|
|
|
run.createFile(t, "dir/file", "1")
|
|
|
|
run.createFile(t, "otherdir/file", "1")
|
|
|
|
|
|
|
|
dm := newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1")
|
|
|
|
localDm := make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
err := run.fremote.Mkdir("dir/subdir")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-05-07 12:04:20 +00:00
|
|
|
root, err := run.filesys.Root()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2017-05-04 20:49:06 +00:00
|
|
|
// expect newly created "subdir" on remote to not show up
|
2017-05-07 12:04:20 +00:00
|
|
|
root.ForgetPath("otherdir")
|
2017-05-04 20:49:06 +00:00
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
2017-05-07 12:04:20 +00:00
|
|
|
root.ForgetPath("dir")
|
2017-05-04 20:49:06 +00:00
|
|
|
dm = newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1|dir/subdir/")
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
run.rm(t, "otherdir/file")
|
|
|
|
run.rmdir(t, "otherdir")
|
|
|
|
run.rm(t, "dir/file")
|
|
|
|
run.rmdir(t, "dir/subdir")
|
|
|
|
run.rmdir(t, "dir")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDirCacheFlushOnDirRename(t *testing.T) {
|
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
run.mkdir(t, "dir")
|
|
|
|
run.createFile(t, "dir/file", "1")
|
|
|
|
|
|
|
|
dm := newDirMap("dir/|dir/file 1")
|
|
|
|
localDm := make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
// expect remotely created directory to not show up
|
|
|
|
err := run.fremote.Mkdir("dir/subdir")
|
|
|
|
require.NoError(t, err)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
err = os.Rename(run.path("dir"), run.path("rid"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
dm = newDirMap("rid/|rid/subdir/|rid/file 1")
|
|
|
|
localDm = make(dirMap)
|
|
|
|
run.readLocal(t, localDm, "")
|
|
|
|
assert.Equal(t, dm, localDm, "expected vs fuse mount")
|
|
|
|
|
|
|
|
run.rm(t, "rid/file")
|
|
|
|
run.rmdir(t, "rid/subdir")
|
|
|
|
run.rmdir(t, "rid")
|
|
|
|
run.checkDir(t, "")
|
|
|
|
}
|