diff options
Diffstat (limited to 'test/python')
-rw-r--r-- | test/python/docker/compat/test_containers.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/python/docker/compat/test_containers.py b/test/python/docker/compat/test_containers.py index be70efa67..511ab1451 100644 --- a/test/python/docker/compat/test_containers.py +++ b/test/python/docker/compat/test_containers.py @@ -1,13 +1,18 @@ +import io import subprocess import sys import time import unittest +from typing import IO, Optional from docker import DockerClient, errors +from docker.models.containers import Container from test.python.docker import Podman from test.python.docker.compat import common, constant +import tarfile + class TestContainers(unittest.TestCase): podman = None # initialized podman configuration for tests @@ -198,3 +203,37 @@ class TestContainers(unittest.TestCase): filters = {"name": "top"} ctnrs = self.client.containers.list(all=True, filters=filters) self.assertEqual(len(ctnrs), 1) + + def test_copy_to_container(self): + ctr: Optional[Container] = None + try: + test_file_content = b"Hello World!" + ctr = self.client.containers.create(image="alpine", detach=True, command="top") + ctr.start() + + buff: IO[bytes] = io.BytesIO() + with tarfile.open(fileobj=buff, mode="w:") as tf: + ti: tarfile.TarInfo = tarfile.TarInfo() + ti.uid = 1042 + ti.gid = 1043 + ti.name = "a.txt" + ti.path = "a.txt" + ti.mode = 0o644 + ti.type = tarfile.REGTYPE + ti.size = len(test_file_content) + tf.addfile(ti, fileobj=io.BytesIO(test_file_content)) + + buff.seek(0) + ctr.put_archive("/tmp/", buff) + ret, out = ctr.exec_run(["stat", "-c", "%u:%g", "/tmp/a.txt"]) + + self.assertEqual(ret, 0) + self.assertTrue(out.startswith(b'1042:1043'), "assert correct uid/gid") + + ret, out = ctr.exec_run(["cat", "/tmp/a.txt"]) + self.assertEqual(ret, 0) + self.assertTrue(out.startswith(test_file_content), "assert file content") + finally: + if ctr is not None: + ctr.stop() + ctr.remove() |