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:
Kir Kolyshkin 2023-05-09 15:12:32 -07:00
parent 4bb0239279
commit 404e844468

View File

@ -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)
}
}