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.

88 lines
2.0 KiB

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