diff --git a/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go b/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go index 973b8b640b8..3baea376ee2 100644 --- a/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go +++ b/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go @@ -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) + } +}