leveldb_store_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 := &LevelDBStore{}
  14. store.initialize(dir)
  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, false); 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 := &LevelDBStore{}
  58. store.initialize(dir)
  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. }