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.

61 lines
1.3 KiB

7 years ago
  1. package leveldb
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer2"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. )
  8. func TestCreateAndFind(t *testing.T) {
  9. filer := filer2.NewFiler(nil)
  10. dir, _ := ioutil.TempDir("", "seaweedfs_filer_test")
  11. defer os.RemoveAll(dir)
  12. store := &LevelDBStore{}
  13. store.initialize(dir)
  14. filer.SetStore(store)
  15. filer.DisableDirectoryCache()
  16. fullpath := filer2.FullPath("/home/chris/this/is/one/file1.jpg")
  17. entry1 := &filer2.Entry{
  18. FullPath: fullpath,
  19. Attr: filer2.Attr{
  20. Mode: 0440,
  21. Uid: 1234,
  22. Gid: 5678,
  23. },
  24. }
  25. if err := filer.CreateEntry(entry1); err != nil {
  26. t.Errorf("create entry %v: %v", entry1.FullPath, err)
  27. return
  28. }
  29. entry, err := filer.FindEntry(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, _ := filer.ListDirectoryEntries(filer2.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, _ = filer.ListDirectoryEntries(filer2.FullPath("/"), "", false, 100)
  46. if len(entries) != 1 {
  47. t.Errorf("list entries count: %v", len(entries))
  48. return
  49. }
  50. }