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.

90 lines
1.9 KiB

  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. }
  12. func TestFsCache(t *testing.T) {
  13. cache := newFsCache(nil)
  14. x := cache.GetFsNode(util.FullPath("/y/x"))
  15. if x != nil {
  16. t.Errorf("wrong node!")
  17. }
  18. p := util.FullPath("/a/b/c")
  19. cache.SetFsNode(p, &File{Name: "cc"})
  20. tNode := cache.GetFsNode(p)
  21. tFile := tNode.(*File)
  22. if tFile.Name != "cc" {
  23. t.Errorf("expecting a FsNode")
  24. }
  25. cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
  26. cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
  27. cache.SetFsNode(util.FullPath("/a/b/f"), &File{Name: "ff"})
  28. cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
  29. cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})
  30. b := cache.GetFsNode(util.FullPath("/a/b"))
  31. if b != nil {
  32. t.Errorf("unexpected node!")
  33. }
  34. a := cache.GetFsNode(util.FullPath("/a"))
  35. if a == nil {
  36. t.Errorf("missing node!")
  37. }
  38. cache.DeleteFsNode(util.FullPath("/a"))
  39. if b != nil {
  40. t.Errorf("unexpected node!")
  41. }
  42. a = cache.GetFsNode(util.FullPath("/a"))
  43. if a != nil {
  44. t.Errorf("wrong DeleteFsNode!")
  45. }
  46. z := cache.GetFsNode(util.FullPath("/z"))
  47. if z == nil {
  48. t.Errorf("missing node!")
  49. }
  50. y := cache.GetFsNode(util.FullPath("/x/y"))
  51. if y != nil {
  52. t.Errorf("wrong node!")
  53. }
  54. }
  55. func TestFsCacheMove(t *testing.T) {
  56. cache := newFsCache(nil)
  57. cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
  58. cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
  59. cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
  60. cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})
  61. cache.Move(util.FullPath("/a/b"), util.FullPath("/z/x"))
  62. d := cache.GetFsNode(util.FullPath("/z/x/d"))
  63. if d == nil {
  64. t.Errorf("unexpected nil node!")
  65. }
  66. if d.(*File).Name != "dd" {
  67. t.Errorf("unexpected non dd node!")
  68. }
  69. }