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.

87 lines
2.0 KiB

5 years ago
4 years ago
5 years ago
3 years ago
6 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
3 years ago
6 years ago
4 years ago
  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. }