inode_to_path_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package mount
  2. import (
  3. "github.com/seaweedfs/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: "actual case",
  16. entry: InodeEntry{
  17. paths: []util.FullPath{"/pjd/nx", "/pjd/n0"},
  18. },
  19. p: "/pjd/nx",
  20. want: true,
  21. count: 1,
  22. },
  23. {
  24. name: "empty",
  25. entry: InodeEntry{},
  26. p: "x",
  27. want: false,
  28. count: 0,
  29. },
  30. {
  31. name: "single",
  32. entry: InodeEntry{
  33. paths: []util.FullPath{"/x"},
  34. },
  35. p: "/x",
  36. want: true,
  37. count: 0,
  38. },
  39. {
  40. name: "first",
  41. entry: InodeEntry{
  42. paths: []util.FullPath{"/x", "/y", "/z"},
  43. },
  44. p: "/x",
  45. want: true,
  46. count: 2,
  47. },
  48. {
  49. name: "middle",
  50. entry: InodeEntry{
  51. paths: []util.FullPath{"/x", "/y", "/z"},
  52. },
  53. p: "/y",
  54. want: true,
  55. count: 2,
  56. },
  57. {
  58. name: "last",
  59. entry: InodeEntry{
  60. paths: []util.FullPath{"/x", "/y", "/z"},
  61. },
  62. p: "/z",
  63. want: true,
  64. count: 2,
  65. },
  66. {
  67. name: "not found",
  68. entry: InodeEntry{
  69. paths: []util.FullPath{"/x", "/y", "/z"},
  70. },
  71. p: "/t",
  72. want: false,
  73. count: 3,
  74. },
  75. }
  76. for _, tt := range tests {
  77. t.Run(tt.name, func(t *testing.T) {
  78. if got := tt.entry.removeOnePath(tt.p); got != tt.want {
  79. t.Errorf("removeOnePath() = %v, want %v", got, tt.want)
  80. }
  81. if tt.count != len(tt.entry.paths) {
  82. t.Errorf("removeOnePath path count = %v, want %v", len(tt.entry.paths), tt.count)
  83. }
  84. for i, p := range tt.entry.paths {
  85. if p == tt.p {
  86. t.Errorf("removeOnePath found path still exists at %v, %v", i, p)
  87. }
  88. }
  89. })
  90. }
  91. }