mirror of
https://github.com/containers/podman.git
synced 2025-05-24 02:27:00 +08:00
Implement --archive flag for podman cp
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user