leveldb2_store_test.go 2.0 KB

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