summaryrefslogtreecommitdiffstats
path: root/tests/test_path.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:54:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:58:39 +0000
commit129a1fb4dbc375be0fa926964aa1be46a0cdbbef (patch)
tree04c0088df47415b24a5be1325d3656b8c3881c04 /tests/test_path.py
parentInitial commit. (diff)
downloaddebputy-129a1fb4dbc375be0fa926964aa1be46a0cdbbef.tar.xz
debputy-129a1fb4dbc375be0fa926964aa1be46a0cdbbef.zip
Adding upstream version 0.1.21.upstream/0.1.21
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_path.py')
-rw-r--r--tests/test_path.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_path.py b/tests/test_path.py
new file mode 100644
index 0000000..a9e826e
--- /dev/null
+++ b/tests/test_path.py
@@ -0,0 +1,47 @@
+from typing import cast
+
+import pytest
+
+from debputy.exceptions import SymlinkLoopError
+from debputy.filesystem_scan import VirtualPathBase
+from debputy.plugin.api import virtual_path_def
+from debputy.plugin.api.test_api import build_virtual_file_system
+
+
+def test_symlink_lookup() -> None:
+ fs = build_virtual_file_system(
+ [
+ virtual_path_def("./usr/share/doc/bar", link_target="foo"),
+ "./usr/share/doc/foo/copyright",
+ virtual_path_def("./usr/share/bar/data", link_target="../foo/data"),
+ "./usr/share/foo/data/foo.dat",
+ virtual_path_def("./usr/share/baz/data", link_target="/usr/share/foo/data"),
+ virtual_path_def(
+ "./usr/share/test/loop-a", link_target="/usr/share/test/loop-b"
+ ),
+ virtual_path_def("./usr/share/test/loop-b", link_target="./loop-c"),
+ virtual_path_def("./usr/share/test/loop-c", link_target="../test/loop-a"),
+ ]
+ )
+ assert fs.lookup("/usr/share/doc/bar/copyright") is not None
+ assert fs.lookup("/usr/share/bar/data/foo.dat") is not None
+ assert fs.lookup("/usr/share/baz/data/foo.dat") is not None
+
+ vp_fs: VirtualPathBase = cast("VirtualPathBase", fs)
+ p, missing = vp_fs.attempt_lookup("/usr/share/doc/foo/non-existent")
+ assert p.path == "./usr/share/doc/foo"
+ assert missing == ["non-existent"]
+
+ p, missing = vp_fs.attempt_lookup("/usr/share/bar/data/non-existent")
+ assert p.path == "./usr/share/foo/data"
+ assert missing == ["non-existent"]
+
+ p, missing = vp_fs.attempt_lookup("/usr/share/baz/data/non-existent")
+ assert p.path == "./usr/share/foo/data"
+ assert missing == ["non-existent"]
+
+ # The symlink can be looked up
+ assert fs.lookup("./usr/share/test/loop-a") is not None
+ with pytest.raises(SymlinkLoopError):
+ # But resolving it will cause issues
+ fs.lookup("./usr/share/test/loop-a/")