MCPcopy
hub / github.com/opencontainers/runc / TestLexicallyStripRoot

Function TestLexicallyStripRoot

internal/pathrs/path_test.go:87–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestLexicallyStripRoot(t *testing.T) {
88 for _, test := range []struct {
89 root, path, out string
90 }{
91 // Works with multiple components.
92 {"/a/b", "/a/b/c", "/c"},
93 {"/hello/world", "/hello/world/the/quick-brown/fox", "/the/quick-brown/fox"},
94 // '/' must be a no-op.
95 {"/", "/a/b/c", "/a/b/c"},
96 // Must be the correct order.
97 {"/a/b", "/a/c/b", "/a/c/b"},
98 // Must be at start.
99 {"/abc/def", "/foo/abc/def/bar", "/foo/abc/def/bar"},
100 // Must be a lexical parent.
101 {"/foo/bar", "/foo/barSAMECOMPONENT", "/foo/barSAMECOMPONENT"},
102 // Must only strip the root once.
103 {"/foo/bar", "/foo/bar/foo/bar/baz", "/foo/bar/baz"},
104 // Deal with .. in a fairly sane way.
105 {"/foo/bar", "/foo/bar/../baz", "/foo/baz"},
106 {"/foo/bar", "../../../../../../foo/bar/baz", "/baz"},
107 {"/foo/bar", "/../../../../../../foo/bar/baz", "/baz"},
108 {"/foo/bar/../baz", "/foo/baz/bar", "/bar"},
109 {"/foo/bar/../baz", "/foo/baz/../bar/../baz/./foo", "/foo"},
110 // All paths are made absolute before stripping.
111 {"foo/bar", "/foo/bar/baz/bee", "/baz/bee"},
112 {"/foo/bar", "foo/bar/baz/beef", "/baz/beef"},
113 {"foo/bar", "foo/bar/baz/beets", "/baz/beets"},
114 } {
115 got := LexicallyStripRoot(test.root, test.path)
116 if got != test.out {
117 t.Errorf("LexicallyStripRoot(%q, %q) -- got %q, expected %q", test.root, test.path, got, test.out)
118 }
119 }
120}

Callers

nothing calls this directly

Calls 1

LexicallyStripRootFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…