diff options
author | Matej Vasek <mvasek@redhat.com> | 2021-06-28 21:17:13 +0200 |
---|---|---|
committer | Matej Vasek <mvasek@redhat.com> | 2021-07-01 12:01:46 +0200 |
commit | 86c6014145d5b8d4ea51f338beb9bddaa8b5a334 (patch) | |
tree | 056769253cf35f00bdd46389bddd9c076c31a00e /test/python/docker | |
parent | fd1715568b7c14451dcf2581c385c8d3e307d30e (diff) | |
download | podman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.tar.gz podman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.tar.bz2 podman-86c6014145d5b8d4ea51f338beb9bddaa8b5a334.zip |
Implement --archive flag for podman cp
Signed-off-by: Matej Vasek <mvasek@redhat.com>
Diffstat (limited to 'test/python/docker')
-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() |