You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dir.go 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package vfstest
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. // TestDirLs checks out listing
  9. func TestDirLs(t *testing.T) {
  10. run.skipIfNoFUSE(t)
  11. run.checkDir(t, "")
  12. run.mkdir(t, "a directory")
  13. run.createFile(t, "a file", "hello")
  14. run.checkDir(t, "a directory/|a file 5")
  15. run.rmdir(t, "a directory")
  16. run.rm(t, "a file")
  17. run.checkDir(t, "")
  18. }
  19. // TestDirCreateAndRemoveDir tests creating and removing a directory
  20. func TestDirCreateAndRemoveDir(t *testing.T) {
  21. run.skipIfNoFUSE(t)
  22. run.mkdir(t, "dir")
  23. run.mkdir(t, "dir/subdir")
  24. run.checkDir(t, "dir/|dir/subdir/")
  25. // Check we can't delete a directory with stuff in
  26. err := run.os.Remove(run.path("dir"))
  27. assert.Error(t, err, "file exists")
  28. // Now delete subdir then dir - should produce no errors
  29. run.rmdir(t, "dir/subdir")
  30. run.checkDir(t, "dir/")
  31. run.rmdir(t, "dir")
  32. run.checkDir(t, "")
  33. }
  34. // TestDirCreateAndRemoveFile tests creating and removing a file
  35. func TestDirCreateAndRemoveFile(t *testing.T) {
  36. run.skipIfNoFUSE(t)
  37. run.mkdir(t, "dir")
  38. run.createFile(t, "dir/file", "potato")
  39. run.checkDir(t, "dir/|dir/file 6")
  40. // Check we can't delete a directory with stuff in
  41. err := run.os.Remove(run.path("dir"))
  42. assert.Error(t, err, "file exists")
  43. // Now delete file
  44. run.rm(t, "dir/file")
  45. run.checkDir(t, "dir/")
  46. run.rmdir(t, "dir")
  47. run.checkDir(t, "")
  48. }
  49. // TestDirRenameFile tests renaming a file
  50. func TestDirRenameFile(t *testing.T) {
  51. run.skipIfNoFUSE(t)
  52. run.mkdir(t, "dir")
  53. run.createFile(t, "file", "potato")
  54. run.checkDir(t, "dir/|file 6")
  55. err := run.os.Rename(run.path("file"), run.path("file2"))
  56. require.NoError(t, err)
  57. run.checkDir(t, "dir/|file2 6")
  58. data := run.readFile(t, "file2")
  59. assert.Equal(t, "potato", data)
  60. err = run.os.Rename(run.path("file2"), run.path("dir/file3"))
  61. require.NoError(t, err)
  62. run.checkDir(t, "dir/|dir/file3 6")
  63. data = run.readFile(t, "dir/file3")
  64. require.NoError(t, err)
  65. assert.Equal(t, "potato", data)
  66. run.rm(t, "dir/file3")
  67. run.rmdir(t, "dir")
  68. run.checkDir(t, "")
  69. }
  70. // TestDirRenameEmptyDir tests renaming and empty directory
  71. func TestDirRenameEmptyDir(t *testing.T) {
  72. run.skipIfNoFUSE(t)
  73. run.mkdir(t, "dir")
  74. run.mkdir(t, "dir1")
  75. run.checkDir(t, "dir/|dir1/")
  76. err := run.os.Rename(run.path("dir1"), run.path("dir/dir2"))
  77. require.NoError(t, err)
  78. run.checkDir(t, "dir/|dir/dir2/")
  79. err = run.os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
  80. require.NoError(t, err)
  81. run.checkDir(t, "dir/|dir/dir3/")
  82. run.rmdir(t, "dir/dir3")
  83. run.rmdir(t, "dir")
  84. run.checkDir(t, "")
  85. }
  86. // TestDirRenameFullDir tests renaming a full directory
  87. func TestDirRenameFullDir(t *testing.T) {
  88. run.skipIfNoFUSE(t)
  89. run.mkdir(t, "dir")
  90. run.mkdir(t, "dir1")
  91. run.createFile(t, "dir1/potato.txt", "maris piper")
  92. run.checkDir(t, "dir/|dir1/|dir1/potato.txt 11")
  93. err := run.os.Rename(run.path("dir1"), run.path("dir/dir2"))
  94. require.NoError(t, err)
  95. run.checkDir(t, "dir/|dir/dir2/|dir/dir2/potato.txt 11")
  96. err = run.os.Rename(run.path("dir/dir2"), run.path("dir/dir3"))
  97. require.NoError(t, err)
  98. run.checkDir(t, "dir/|dir/dir3/|dir/dir3/potato.txt 11")
  99. run.rm(t, "dir/dir3/potato.txt")
  100. run.rmdir(t, "dir/dir3")
  101. run.rmdir(t, "dir")
  102. run.checkDir(t, "")
  103. }
  104. // TestDirModTime tests mod times
  105. func TestDirModTime(t *testing.T) {
  106. run.skipIfNoFUSE(t)
  107. run.mkdir(t, "dir")
  108. mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
  109. err := run.os.Chtimes(run.path("dir"), mtime, mtime)
  110. require.NoError(t, err)
  111. info, err := run.os.Stat(run.path("dir"))
  112. require.NoError(t, err)
  113. // avoid errors because of timezone differences
  114. assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
  115. run.rmdir(t, "dir")
  116. }
  117. /*
  118. // TestDirCacheFlush tests flushing the dir cache
  119. func TestDirCacheFlush(t *testing.T) {
  120. run.skipIfNoFUSE(t)
  121. run.checkDir(t, "")
  122. run.mkdir(t, "dir")
  123. run.mkdir(t, "otherdir")
  124. run.createFile(t, "dir/file", "1")
  125. run.createFile(t, "otherdir/file", "1")
  126. dm := newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1")
  127. localDm := make(dirMap)
  128. run.readLocal(t, localDm, "")
  129. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  130. err := run.fremote.Mkdir(context.Background(), "dir/subdir")
  131. require.NoError(t, err)
  132. // expect newly created "subdir" on remote to not show up
  133. run.forget("otherdir")
  134. run.readLocal(t, localDm, "")
  135. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  136. run.forget("dir")
  137. dm = newDirMap("otherdir/|otherdir/file 1|dir/|dir/file 1|dir/subdir/")
  138. run.readLocal(t, localDm, "")
  139. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  140. run.rm(t, "otherdir/file")
  141. run.rmdir(t, "otherdir")
  142. run.rm(t, "dir/file")
  143. run.rmdir(t, "dir/subdir")
  144. run.rmdir(t, "dir")
  145. run.checkDir(t, "")
  146. }
  147. // TestDirCacheFlushOnDirRename tests flushing the dir cache on rename
  148. func TestDirCacheFlushOnDirRename(t *testing.T) {
  149. run.skipIfNoFUSE(t)
  150. run.mkdir(t, "dir")
  151. run.createFile(t, "dir/file", "1")
  152. dm := newDirMap("dir/|dir/file 1")
  153. localDm := make(dirMap)
  154. run.readLocal(t, localDm, "")
  155. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  156. // expect remotely created directory to not show up
  157. err := run.fremote.Mkdir(context.Background(), "dir/subdir")
  158. require.NoError(t, err)
  159. run.readLocal(t, localDm, "")
  160. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  161. err = run.os.Rename(run.path("dir"), run.path("rid"))
  162. require.NoError(t, err)
  163. dm = newDirMap("rid/|rid/subdir/|rid/file 1")
  164. localDm = make(dirMap)
  165. run.readLocal(t, localDm, "")
  166. assert.Equal(t, dm, localDm, "expected vs fuse mount")
  167. run.rm(t, "rid/file")
  168. run.rmdir(t, "rid/subdir")
  169. run.rmdir(t, "rid")
  170. run.checkDir(t, "")
  171. }
  172. */

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。