aboutsummaryrefslogtreecommitdiff
path: root/test/python
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-07-01 13:15:00 -0400
committerGitHub <noreply@github.com>2021-07-01 13:15:00 -0400
commit955c1d2bfeac0c399bbc4d82fd7b72ed4cc868d3 (patch)
tree1758a6acf60589fa13ae95dd39e3a0e1ddc78c13 /test/python
parenta855b30f81cc72e67fc40b7301b98124ab0e6d01 (diff)
parent86c6014145d5b8d4ea51f338beb9bddaa8b5a334 (diff)
downloadpodman-955c1d2bfeac0c399bbc4d82fd7b72ed4cc868d3.tar.gz
podman-955c1d2bfeac0c399bbc4d82fd7b72ed4cc868d3.tar.bz2
podman-955c1d2bfeac0c399bbc4d82fd7b72ed4cc868d3.zip
Merge pull request #10804 from matejvasek/fix-cp-sub-cmd
Implement --archive flag for podman cp
Diffstat (limited to 'test/python')
-rw-r--r--test/python/docker/compat/test_containers.py39
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()