Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI committed Sep 19, 2024
1 parent c0c9dfa commit f66885a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/_data/plugins/apps/container/docker/docker.tgz
Git LFS file not shown
26 changes: 21 additions & 5 deletions tests/filesystems/test_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


def test_overlay_filesystem_docker_container(target_linux_docker: Target) -> None:
mount_path = list(target_linux_docker.fs.path("/var/lib/docker/image/overlay2/layerdb/mounts/").iterdir())[0]
mount_path = target_linux_docker.fs.path("/var/lib/docker/image/overlay2/layerdb/mounts/f988f88e221d97930a665712cf16ab520f7e2c5af395660c145df93aebedf071") # noqa: E501
fs = Overlay2Filesystem(mount_path)

assert fs.__type__ == "overlay2"
assert len(fs.layers) == 4
assert len(fs.layers) == 9

assert sorted([str(p) for p in fs.path("/").iterdir()]) == sorted(
[
Expand All @@ -29,13 +29,14 @@ def test_overlay_filesystem_docker_container(target_linux_docker: Target) -> Non
"/usr",
"/srv",
"/.dockerenv",
"/container",
]
)

assert [str(p) for p in fs.path("/root").iterdir()] == [
"/root/secret.txt",
"/root/file.txt",
assert sorted([str(p) for p in fs.path("/root").iterdir()]) == [
"/root/.ash_history",
"/root/file.txt",
"/root/secret.txt",
]

assert fs.path("/root/secret.txt").open().read() == b"this is a secret!\n"
Expand All @@ -47,3 +48,18 @@ def test_overlay_filesystem_docker_container(target_linux_docker: Target) -> Non
assert fs.path("/bin/sh").readlink() == fs.path("/bin/busybox")
assert fs.path("/etc/ssl/cert.pem").resolve() == fs.path("/etc/ssl/certs/ca-certificates.crt")
assert fs.path("/usr/lib/libcrypto.so.3").resolve() == fs.path("/lib/libcrypto.so.3")

# test if standard mounts were correctly added
assert fs.path("/etc/hostname").exists()
assert fs.path("/etc/hostname").is_file()
assert fs.path("/etc/hostname").read_text() == "f988f88e221d\n"
assert fs.path("/etc/hosts").exists()
assert fs.path("/etc/resolv.conf").exists()

# test if custom mounts were correctly added
assert fs.path("/container/file.txt").exists()
assert fs.path("/container/file.txt").is_file()
assert fs.path("/container/folder").exists()
assert fs.path("/container/folder").is_dir()
assert fs.path("/container/folder/some-file.txt").exists()
assert fs.path("/container/folder/some-file.txt").is_file()

0 comments on commit f66885a

Please sign in to comment.