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.

90 lines
2.0 KiB

5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
  1. package leveldb
  2. import (
  3. "context"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. "github.com/chrislusf/seaweedfs/weed/filer2"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func TestCreateAndFind(t *testing.T) {
  11. filer := filer2.NewFiler(nil, nil, "", 0, "", "", nil)
  12. dir, _ := ioutil.TempDir("", "seaweedfs_filer_test")
  13. defer os.RemoveAll(dir)
  14. store := &LevelDB2Store{}
  15. store.initialize(dir, 2)
  16. filer.SetStore(store)
  17. filer.DisableDirectoryCache()
  18. fullpath := util.FullPath("/home/chris/this/is/one/file1.jpg")
  19. ctx := context.Background()
  20. entry1 := &filer2.Entry{
  21. FullPath: fullpath,
  22. Attr: filer2.Attr{
  23. Mode: 0440,
  24. Uid: 1234,
  25. Gid: 5678,
  26. },
  27. }
  28. if err := filer.CreateEntry(ctx, entry1, false); err != nil {
  29. t.Errorf("create entry %v: %v", entry1.FullPath, err)
  30. return
  31. }
  32. entry, err := filer.FindEntry(ctx, fullpath)
  33. if err != nil {
  34. t.Errorf("find entry: %v", err)
  35. return
  36. }
  37. if entry.FullPath != entry1.FullPath {
  38. t.Errorf("find wrong entry: %v", entry.FullPath)
  39. return
  40. }
  41. // checking one upper directory
  42. entries, _ := filer.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100)
  43. if len(entries) != 1 {
  44. t.Errorf("list entries count: %v", len(entries))
  45. return
  46. }
  47. // checking one upper directory
  48. entries, _ = filer.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100)
  49. if len(entries) != 1 {
  50. t.Errorf("list entries count: %v", len(entries))
  51. return
  52. }
  53. }
  54. func TestEmptyRoot(t *testing.T) {
  55. filer := filer2.NewFiler(nil, nil, "", 0, "", "", nil)
  56. dir, _ := ioutil.TempDir("", "seaweedfs_filer_test2")
  57. defer os.RemoveAll(dir)
  58. store := &LevelDB2Store{}
  59. store.initialize(dir, 2)
  60. filer.SetStore(store)
  61. filer.DisableDirectoryCache()
  62. ctx := context.Background()
  63. // checking one upper directory
  64. entries, err := filer.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100)
  65. if err != nil {
  66. t.Errorf("list entries: %v", err)
  67. return
  68. }
  69. if len(entries) != 0 {
  70. t.Errorf("list entries count: %v", len(entries))
  71. return
  72. }
  73. }