diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/models_containers_test.py | 23 | ||||
-rw-r--r-- | tests/unit/fake_api_client.py | 2 | ||||
-rw-r--r-- | tests/unit/models_containers_test.py | 7 |
3 files changed, 24 insertions, 8 deletions
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py index ce3349b..7707ae2 100644 --- a/tests/integration/models_containers_test.py +++ b/tests/integration/models_containers_test.py @@ -1,7 +1,7 @@ import docker import tempfile from .base import BaseIntegrationTest, TEST_API_VERSION -from ..helpers import random_name +from ..helpers import random_name, requires_api_version class ContainerCollectionTest(BaseIntegrationTest): @@ -95,7 +95,7 @@ class ContainerCollectionTest(BaseIntegrationTest): "alpine", "echo hello", log_config=dict(type='none') ) - self.assertEqual(out, None) + assert out is None def test_run_with_json_file_driver(self): client = docker.from_env(version=TEST_API_VERSION) @@ -104,7 +104,24 @@ class ContainerCollectionTest(BaseIntegrationTest): "alpine", "echo hello", log_config=dict(type='json-file') ) - self.assertEqual(out, b'hello\n') + assert out == b'hello\n' + + @requires_api_version('1.25') + def test_run_with_auto_remove(self): + client = docker.from_env(version=TEST_API_VERSION) + out = client.containers.run( + 'alpine', 'echo hello', auto_remove=True + ) + assert out == b'hello\n' + + def test_run_with_streamed_logs(self): + client = docker.from_env(version=TEST_API_VERSION) + out = client.containers.run( + 'alpine', 'sh -c "echo hello && echo world"', stream=True + ) + logs = [line for line in out] + assert logs[0] == b'hello\n' + assert logs[1] == b'world\n' def test_get(self): client = docker.from_env(version=TEST_API_VERSION) diff --git a/tests/unit/fake_api_client.py b/tests/unit/fake_api_client.py index 47890ac..f908355 100644 --- a/tests/unit/fake_api_client.py +++ b/tests/unit/fake_api_client.py @@ -43,7 +43,7 @@ def make_fake_api_client(): fake_api.get_fake_inspect_container()[1], 'inspect_image.return_value': fake_api.get_fake_inspect_image()[1], 'inspect_network.return_value': fake_api.get_fake_network()[1], - 'logs.return_value': 'hello world\n', + 'logs.return_value': [b'hello world\n'], 'networks.return_value': fake_api.get_fake_network_list()[1], 'start.return_value': None, 'wait.return_value': 0, diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 5eaa45a..a479e83 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -12,7 +12,7 @@ class ContainerCollectionTest(unittest.TestCase): client = make_fake_client() out = client.containers.run("alpine", "echo hello world") - assert out == 'hello world\n' + assert out == b'hello world\n' client.api.create_container.assert_called_with( image="alpine", @@ -24,9 +24,8 @@ class ContainerCollectionTest(unittest.TestCase): client.api.start.assert_called_with(FAKE_CONTAINER_ID) client.api.wait.assert_called_with(FAKE_CONTAINER_ID) client.api.logs.assert_called_with( - FAKE_CONTAINER_ID, - stderr=False, - stdout=True + FAKE_CONTAINER_ID, stderr=False, stdout=True, stream=True, + follow=True ) def test_create_container_args(self): |