leveldb3_store_test.go 2.0 KB

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