Exemple #1
0
 def test_run_container_error(self, docker_client: DockerClient):
     container_name = _random_container_name()
     try:
         with pytest.raises(ContainerException) as ex:
             docker_client.run_container(
                 "alpine",
                 name=container_name,
                 command=["./doesnotexist"],
             )
         assert ex.match("doesnotexist: no such file or directory")
     finally:
         docker_client.remove_container(container_name)
Exemple #2
0
 def test_run_container(self, docker_client: DockerClient):
     container_name = _random_container_name()
     try:
         output, _ = docker_client.run_container(
             "alpine",
             name=container_name,
             command=["echo", "foobared"],
         )
         output = output.decode(config.DEFAULT_ENCODING)
         assert "foobared" in output
     finally:
         docker_client.remove_container(container_name)
Exemple #3
0
    def test_run_container_with_stdin(self, docker_client: DockerClient):
        container_name = _random_container_name()
        message = "test_message_stdin"
        try:
            output, _ = docker_client.run_container(
                "alpine",
                name=container_name,
                interactive=True,
                stdin=message.encode(config.DEFAULT_ENCODING),
                command=["cat"],
            )

            assert message == output.decode(config.DEFAULT_ENCODING).strip()
        finally:
            docker_client.remove_container(container_name)
Exemple #4
0
    def test_run_detached_with_logs(self, docker_client: DockerClient):
        container_name = _random_container_name()
        message = "test_message"
        try:
            output, _ = docker_client.run_container(
                "alpine",
                name=container_name,
                detach=True,
                command=["echo", message],
            )
            container_id = output.decode(config.DEFAULT_ENCODING).strip()
            logs = docker_client.get_container_logs(container_id)

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