Пример #1
0
 def test_copy_from_non_existent_container(self, tmpdir,
                                           docker_client: ContainerClient):
     local_path = tmpdir.mkdir("test_dir")
     with pytest.raises(NoSuchContainer):
         docker_client.copy_from_container(
             "hopefully_non_existent_container_%s" % short_uid(),
             str(local_path), "test_file")
Пример #2
0
 def _test_copy_from_container(
     self,
     local_path,
     file_path,
     container_file_name,
     docker_client: ContainerClient,
     dummy_container,
 ):
     docker_client.exec_in_container(
         dummy_container.container_id,
         command=["sh", "-c", f"echo TEST_CONTENT > {container_file_name}"],
     )
     docker_client.copy_from_container(
         dummy_container.container_id,
         local_path=str(local_path),
         container_path=container_file_name,
     )
     assert "TEST_CONTENT" == file_path.read().strip()
Пример #3
0
    def test_create_start_container_with_stdin_to_file(
            self, tmpdir, docker_client: ContainerClient):
        container_name = _random_container_name()
        message = "test_message_stdin"
        try:
            docker_client.create_container(
                "alpine",
                name=container_name,
                interactive=True,
                command=["sh", "-c", "cat > test_file"],
            )

            output, _ = docker_client.start_container(
                container_name,
                interactive=True,
                stdin=message.encode(config.DEFAULT_ENCODING))
            target_path = tmpdir.join("test_file")
            docker_client.copy_from_container(container_name, str(target_path),
                                              "test_file")

            assert message == target_path.read().strip()
        finally:
            docker_client.remove_container(container_name)