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
1.9 KiB

6 years ago
6 years ago
  1. package leveldb
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer2"
  5. "io/ioutil"
  6. "os"
  7. "testing"
  8. )
  9. func TestCreateAndFind(t *testing.T) {
  10. filer := filer2.NewFiler(nil, nil)
  11. dir, _ := ioutil.TempDir("", "seaweedfs_filer_test")
  12. defer os.RemoveAll(dir)
  13. store := &LevelDB2Store{}
  14. store.initialize(dir,2)
  15. filer.SetStore(store)
  16. filer.DisableDirectoryCache()
  17. fullpath := filer2.FullPath("/home/chris/this/is/one/file1.jpg")
  18. ctx := context.Background()
  19. entry1 := &filer2.Entry{
  20. FullPath: fullpath,
  21. Attr: filer2.Attr{
  22. Mode: 0440,
  23. Uid: 1234,
  24. Gid: 5678,
  25. },
  26. }
  27. if err := filer.CreateEntry(ctx, entry1); err != nil {
  28. t.Errorf("create entry %v: %v", entry1.FullPath, err)
  29. return
  30. }
  31. entry, err := filer.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, _ := filer.ListDirectoryEntries(ctx, filer2.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, _ = filer.ListDirectoryEntries(ctx, filer2.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. filer := filer2.NewFiler(nil, nil)
  55. dir, _ := ioutil.TempDir("", "seaweedfs_filer_test2")
  56. defer os.RemoveAll(dir)
  57. store := &LevelDB2Store{}
  58. store.initialize(dir,2)
  59. filer.SetStore(store)
  60. filer.DisableDirectoryCache()
  61. ctx := context.Background()
  62. // checking one upper directory
  63. entries, err := filer.ListDirectoryEntries(ctx, filer2.FullPath("/"), "", false, 100)
  64. if err != nil {
  65. t.Errorf("list entries: %v", err)
  66. return
  67. }
  68. if len(entries) != 0 {
  69. t.Errorf("list entries count: %v", len(entries))
  70. return
  71. }
  72. }