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.

79 lines
1.4 KiB

  1. package mount
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/util"
  4. "testing"
  5. )
  6. func TestInodeEntry_removeOnePath(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. entry InodeEntry
  10. p util.FullPath
  11. want bool
  12. count int
  13. }{
  14. {
  15. name: "empty",
  16. entry: InodeEntry{},
  17. p: "x",
  18. want: false,
  19. count: 0,
  20. },
  21. {
  22. name: "single",
  23. entry: InodeEntry{
  24. paths: []util.FullPath{"/x"},
  25. },
  26. p: "/x",
  27. want: true,
  28. count: 0,
  29. },
  30. {
  31. name: "first",
  32. entry: InodeEntry{
  33. paths: []util.FullPath{"/x", "/y", "/z"},
  34. },
  35. p: "/x",
  36. want: true,
  37. count: 2,
  38. },
  39. {
  40. name: "middle",
  41. entry: InodeEntry{
  42. paths: []util.FullPath{"/x", "/y", "/z"},
  43. },
  44. p: "/y",
  45. want: true,
  46. count: 2,
  47. },
  48. {
  49. name: "last",
  50. entry: InodeEntry{
  51. paths: []util.FullPath{"/x", "/y", "/z"},
  52. },
  53. p: "/z",
  54. want: true,
  55. count: 2,
  56. },
  57. {
  58. name: "not found",
  59. entry: InodeEntry{
  60. paths: []util.FullPath{"/x", "/y", "/z"},
  61. },
  62. p: "/t",
  63. want: false,
  64. count: 3,
  65. },
  66. }
  67. for _, tt := range tests {
  68. t.Run(tt.name, func(t *testing.T) {
  69. if got := tt.entry.removeOnePath(tt.p); got != tt.want {
  70. t.Errorf("removeOnePath() = %v, want %v", got, tt.want)
  71. }
  72. if tt.count != len(tt.entry.paths) {
  73. t.Errorf("removeOnePath path count = %v, want %v", len(tt.entry.paths), tt.count)
  74. }
  75. })
  76. }
  77. }