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.

84 lines
1.9 KiB

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