def test_container_status(self, run_mock):
     test_output = "Up 2 minutes - localstack_main"
     run_mock.return_value = test_output
     docker_client = CmdDockerClient()
     status = docker_client.get_container_status("localstack_main")
     self.assertEqual(DockerContainerStatus.UP, status)
     run_mock.return_value = "Exited (0) 1 minute ago - localstack_main"
     status = docker_client.get_container_status("localstack_main")
     self.assertEqual(DockerContainerStatus.DOWN, status)
     run_mock.return_value = "STATUS    NAME"
     status = docker_client.get_container_status("localstack_main")
     self.assertEqual(DockerContainerStatus.NON_EXISTENT, status)
Example #2
0
    def test_container_lifecycle_commands(self, docker_client: DockerClient):
        container_name = _random_container_name()
        output = docker_client.create_container(
            "alpine",
            name=container_name,
            command=["sh", "-c", "for i in `seq 30`; do sleep 1; echo $i; done"],
        )
        container_id = output.strip()
        assert container_id

        try:
            docker_client.start_container(container_id)
            assert DockerContainerStatus.UP == docker_client.get_container_status(container_name)
            docker_client.stop_container(container_id)
            assert DockerContainerStatus.DOWN == docker_client.get_container_status(container_name)
        finally:
            docker_client.remove_container(container_id)

        assert DockerContainerStatus.NON_EXISTENT == docker_client.get_container_status(
            container_name
        )