fscache_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package filesys
  2. import (
  3. "testing"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. )
  6. func TestPathSplit(t *testing.T) {
  7. parts := util.FullPath("/").Split()
  8. if len(parts) != 0 {
  9. t.Errorf("expecting an empty list, but getting %d", len(parts))
  10. }
  11. parts = util.FullPath("/readme.md").Split()
  12. if len(parts) != 1 {
  13. t.Errorf("expecting an empty list, but getting %d", len(parts))
  14. }
  15. }
  16. func TestFsCache(t *testing.T) {
  17. cache := newFsCache(nil)
  18. x := cache.GetFsNode(util.FullPath("/y/x"))
  19. if x != nil {
  20. t.Errorf("wrong node!")
  21. }
  22. p := util.FullPath("/a/b/c")
  23. cache.SetFsNode(p, &File{Name: "cc"})
  24. tNode := cache.GetFsNode(p)
  25. tFile := tNode.(*File)
  26. if tFile.Name != "cc" {
  27. t.Errorf("expecting a FsNode")
  28. }
  29. cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
  30. cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
  31. cache.SetFsNode(util.FullPath("/a/b/f"), &File{Name: "ff"})
  32. cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
  33. cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})
  34. b := cache.GetFsNode(util.FullPath("/a/b"))
  35. if b != nil {
  36. t.Errorf("unexpected node!")
  37. }
  38. a := cache.GetFsNode(util.FullPath("/a"))
  39. if a == nil {
  40. t.Errorf("missing node!")
  41. }
  42. cache.DeleteFsNode(util.FullPath("/a"))
  43. if b != nil {
  44. t.Errorf("unexpected node!")
  45. }
  46. a = cache.GetFsNode(util.FullPath("/a"))
  47. if a != nil {
  48. t.Errorf("wrong DeleteFsNode!")
  49. }
  50. z := cache.GetFsNode(util.FullPath("/z"))
  51. if z == nil {
  52. t.Errorf("missing node!")
  53. }
  54. y := cache.GetFsNode(util.FullPath("/x/y"))
  55. if y != nil {
  56. t.Errorf("wrong node!")
  57. }
  58. }
  59. func TestFsCacheMove(t *testing.T) {
  60. cache := newFsCache(nil)
  61. cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
  62. cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
  63. cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
  64. cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})
  65. cache.Move(util.FullPath("/a/b"), util.FullPath("/z/x"))
  66. d := cache.GetFsNode(util.FullPath("/z/x/d"))
  67. if d == nil {
  68. t.Errorf("unexpected nil node!")
  69. }
  70. if d.(*File).Name != "dd" {
  71. t.Errorf("unexpected non dd node!")
  72. }
  73. }