mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 14:23:37 +00:00
mount-utils: add isMountPointMatch test and benchmark
Add some test cases for isMountPointMatch, to prepare for its rework. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
4bb0239279
commit
404e844468
@ -332,3 +332,35 @@ func TestBadParseMountInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testIsMountPointMatch(t testing.TB) {
|
||||
mpCases := []struct {
|
||||
mp, dir string
|
||||
res bool
|
||||
}{
|
||||
{"", "", true},
|
||||
{"/", "/", true},
|
||||
{"/some/path", "/some/path", true},
|
||||
{"/a/different/kind/of/path\\040(deleted)", "/a/different/kind/of/path", true},
|
||||
{"one", "two", false},
|
||||
{"a somewhat long path that ends with A", "a somewhat long path that ends with B", false},
|
||||
}
|
||||
|
||||
for _, tc := range mpCases {
|
||||
mp := MountPoint{Path: tc.mp}
|
||||
res := isMountPointMatch(mp, tc.dir)
|
||||
if res != tc.res {
|
||||
t.Errorf("mp: %q, dir: %q, expected %v, got %v", tc.mp, tc.dir, tc.res, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsMountPointMatch(t *testing.T) {
|
||||
testIsMountPointMatch(t)
|
||||
}
|
||||
|
||||
func BenchmarkIsMountPointMatch(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
testIsMountPointMatch(b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user