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

144 lines
3.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package memdb
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer2"
  4. "testing"
  5. )
  6. func TestCreateAndFind(t *testing.T) {
  7. filer := filer2.NewFiler(nil)
  8. store := &MemDbStore{}
  9. store.Initialize(nil)
  10. filer.SetStore(store)
  11. filer.DisableDirectoryCache()
  12. fullpath := filer2.FullPath("/home/chris/this/is/one/file1.jpg")
  13. entry1 := &filer2.Entry{
  14. FullPath: fullpath,
  15. Attr: filer2.Attr{
  16. Mode: 0440,
  17. Uid: 1234,
  18. Gid: 5678,
  19. },
  20. }
  21. if err := filer.CreateEntry(entry1); err != nil {
  22. t.Errorf("create entry %v: %v", entry1.FullPath, err)
  23. return
  24. }
  25. entry, err := filer.FindEntry(fullpath)
  26. if err != nil {
  27. t.Errorf("find entry: %v", err)
  28. return
  29. }
  30. if entry.FullPath != entry1.FullPath {
  31. t.Errorf("find wrong entry: %v", entry.FullPath)
  32. return
  33. }
  34. }
  35. func TestCreateFileAndList(t *testing.T) {
  36. filer := filer2.NewFiler(nil)
  37. store := &MemDbStore{}
  38. store.Initialize(nil)
  39. filer.SetStore(store)
  40. filer.DisableDirectoryCache()
  41. entry1 := &filer2.Entry{
  42. FullPath: filer2.FullPath("/home/chris/this/is/one/file1.jpg"),
  43. Attr: filer2.Attr{
  44. Mode: 0440,
  45. Uid: 1234,
  46. Gid: 5678,
  47. },
  48. }
  49. entry2 := &filer2.Entry{
  50. FullPath: filer2.FullPath("/home/chris/this/is/one/file2.jpg"),
  51. Attr: filer2.Attr{
  52. Mode: 0440,
  53. Uid: 1234,
  54. Gid: 5678,
  55. },
  56. }
  57. filer.CreateEntry(entry1)
  58. filer.CreateEntry(entry2)
  59. // checking the 2 files
  60. entries, err := filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is/one/"), "", false, 100)
  61. if err != nil {
  62. t.Errorf("list entries: %v", err)
  63. return
  64. }
  65. if len(entries) != 2 {
  66. t.Errorf("list entries count: %v", len(entries))
  67. return
  68. }
  69. if entries[0].FullPath != entry1.FullPath {
  70. t.Errorf("find wrong entry 1: %v", entries[0].FullPath)
  71. return
  72. }
  73. if entries[1].FullPath != entry2.FullPath {
  74. t.Errorf("find wrong entry 2: %v", entries[1].FullPath)
  75. return
  76. }
  77. // checking the offset
  78. entries, err = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is/one/"), "file1.jpg", false, 100)
  79. if len(entries) != 1 {
  80. t.Errorf("list entries count: %v", len(entries))
  81. return
  82. }
  83. // checking one upper directory
  84. entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
  85. if len(entries) != 1 {
  86. t.Errorf("list entries count: %v", len(entries))
  87. return
  88. }
  89. // checking root directory
  90. entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/"), "", false, 100)
  91. if len(entries) != 1 {
  92. t.Errorf("list entries count: %v", len(entries))
  93. return
  94. }
  95. // add file3
  96. file3Path := filer2.FullPath("/home/chris/this/is/file3.jpg")
  97. entry3 := &filer2.Entry{
  98. FullPath: file3Path,
  99. Attr: filer2.Attr{
  100. Mode: 0440,
  101. Uid: 1234,
  102. Gid: 5678,
  103. },
  104. }
  105. filer.CreateEntry(entry3)
  106. // checking one upper directory
  107. entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
  108. if len(entries) != 2 {
  109. t.Errorf("list entries count: %v", len(entries))
  110. return
  111. }
  112. // delete file and count
  113. filer.DeleteEntryMetaAndData(file3Path, false)
  114. entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
  115. if len(entries) != 1 {
  116. t.Errorf("list entries count: %v", len(entries))
  117. return
  118. }
  119. }