|  | 
| 8 | 8 | 
 | 
| 9 | 9 | from testcontainers.core.container import DockerContainer | 
| 10 | 10 | from testcontainers.core.image import DockerImage | 
|  | 11 | +from testcontainers.core.transferable import Transferable | 
| 11 | 12 | from testcontainers.core.waiting_utils import wait_for_logs | 
| 12 | 13 | 
 | 
| 13 | 14 | 
 | 
| @@ -92,3 +93,33 @@ def test_docker_image_with_custom_dockerfile_path(dockerfile_path: Optional[Path | 
| 92 | 93 |             with DockerContainer(str(image)) as container: | 
| 93 | 94 |                 assert container._container.image.short_id.endswith(image_short_id), "Image ID mismatch" | 
| 94 | 95 |                 assert container.get_logs() == (("Hello world!\n").encode(), b""), "Container logs mismatch" | 
|  | 96 | + | 
|  | 97 | + | 
|  | 98 | +def test_docker_start_with_copy_file_to_container_from_binary_transferable(tmp_path: Path) -> None: | 
|  | 99 | +    container = DockerContainer("nginx") | 
|  | 100 | +    data = "test_docker_start_with_copy_file_to_container_from_binary_transferable" | 
|  | 101 | + | 
|  | 102 | +    input_data = data.encode("utf-8") | 
|  | 103 | +    output_file = Path("/tmp/test_docker_start_with_copy_file_to_container_from_binary_transferable.txt") | 
|  | 104 | + | 
|  | 105 | +    container.with_copy_file_to_container(Transferable(input_data, output_file)).start() | 
|  | 106 | + | 
|  | 107 | +    _, stdout = container.exec(f"cat {output_file}") | 
|  | 108 | +    assert stdout.decode() == data | 
|  | 109 | + | 
|  | 110 | + | 
|  | 111 | +def test_docker_start_with_copy_file_to_container_from_file_transferable(tmp_path: Path) -> None: | 
|  | 112 | +    container = DockerContainer("nginx") | 
|  | 113 | +    data = "test_docker_start_with_copy_file_to_container_from_file_transferable" | 
|  | 114 | + | 
|  | 115 | +    with tempfile.NamedTemporaryFile(delete=True) as f: | 
|  | 116 | +        f.write(data.encode("utf-8")) | 
|  | 117 | +        f.seek(0) | 
|  | 118 | + | 
|  | 119 | +        input_file = Path(f.name) | 
|  | 120 | +        output_file = Path("/tmp/test_docker_start_with_copy_file_to_container_from_file_transferable.txt") | 
|  | 121 | + | 
|  | 122 | +        container.with_copy_file_to_container(Transferable(input_file, output_file)).start() | 
|  | 123 | + | 
|  | 124 | +        _, stdout = container.exec(f"cat {output_file}") | 
|  | 125 | +        assert stdout.decode() == data | 
0 commit comments