diff options
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/api_build_test.py | 28 | ||||
-rw-r--r-- | tests/integration/api_container_test.py | 16 | ||||
-rw-r--r-- | tests/integration/api_image_test.py | 16 | ||||
-rw-r--r-- | tests/integration/api_service_test.py | 17 | ||||
-rw-r--r-- | tests/integration/models_containers_test.py | 18 |
5 files changed, 89 insertions, 6 deletions
diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index 609964f..d0aa5c2 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -9,7 +9,7 @@ import pytest import six from .base import BaseAPIIntegrationTest -from ..helpers import requires_api_version +from ..helpers import requires_api_version, requires_experimental class BuildTest(BaseAPIIntegrationTest): @@ -244,6 +244,32 @@ class BuildTest(BaseAPIIntegrationTest): with pytest.raises(errors.NotFound): self.client.inspect_image('dockerpytest_nonebuild') + @requires_experimental(until=None) + @requires_api_version('1.25') + def test_build_squash(self): + script = io.BytesIO('\n'.join([ + 'FROM busybox', + 'RUN echo blah > /file_1', + 'RUN echo blahblah > /file_2', + 'RUN echo blahblahblah > /file_3' + ]).encode('ascii')) + + def build_squashed(squash): + tag = 'squash' if squash else 'nosquash' + stream = self.client.build( + fileobj=script, tag=tag, squash=squash + ) + self.tmp_imgs.append(tag) + for chunk in stream: + pass + + return self.client.inspect_image(tag) + + non_squashed = build_squashed(False) + squashed = build_squashed(True) + self.assertEqual(len(non_squashed['RootFS']['Layers']), 4) + self.assertEqual(len(squashed['RootFS']['Layers']), 2) + def test_build_stderr_data(self): control_chars = ['\x1b[91m', '\x1b[0m'] snippet = 'Ancient Temple (Mystic Oriental Dream ~ Ancient Temple)' diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index f8b474a..a972c1c 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -1092,20 +1092,28 @@ class AttachContainerTest(BaseAPIIntegrationTest): command = "printf '{0}'".format(line) container = self.client.create_container(BUSYBOX, command, detach=True, tty=False) - ident = container['Id'] - self.tmp_containers.append(ident) + self.tmp_containers.append(container) opts = {"stdout": 1, "stream": 1, "logs": 1} - pty_stdout = self.client.attach_socket(ident, opts) + pty_stdout = self.client.attach_socket(container, opts) self.addCleanup(pty_stdout.close) - self.client.start(ident) + self.client.start(container) next_size = next_frame_size(pty_stdout) self.assertEqual(next_size, len(line)) data = read_exactly(pty_stdout, next_size) self.assertEqual(data.decode('utf-8'), line) + def test_attach_no_stream(self): + container = self.client.create_container( + BUSYBOX, 'echo hello' + ) + self.tmp_containers.append(container) + self.client.start(container) + output = self.client.attach(container, stream=False, logs=True) + assert output == 'hello\n'.encode(encoding='ascii') + class PauseTest(BaseAPIIntegrationTest): def test_pause_unpause(self): diff --git a/tests/integration/api_image_test.py b/tests/integration/api_image_test.py index 917bc50..14fb77a 100644 --- a/tests/integration/api_image_test.py +++ b/tests/integration/api_image_test.py @@ -113,7 +113,8 @@ class RemoveImageTest(BaseAPIIntegrationTest): self.assertIn('Id', res) img_id = res['Id'] self.tmp_imgs.append(img_id) - self.client.remove_image(img_id, force=True) + logs = self.client.remove_image(img_id, force=True) + self.assertIn({"Deleted": img_id}, logs) images = self.client.images(all=True) res = [x for x in images if x['Id'].startswith(img_id)] self.assertEqual(len(res), 0) @@ -248,6 +249,19 @@ class ImportImageTest(BaseAPIIntegrationTest): assert img_data['Config']['Cmd'] == ['echo'] assert img_data['Config']['User'] == 'foobar' + # Docs say output is available in 1.23, but this test fails on 1.12.0 + @requires_api_version('1.24') + def test_get_load_image(self): + test_img = 'hello-world:latest' + self.client.pull(test_img) + data = self.client.get_image(test_img) + assert data + output = self.client.load_image(data) + assert any([ + line for line in output + if 'Loaded image: {}'.format(test_img) in line.get('stream', '') + ]) + @contextlib.contextmanager def temporary_http_file_server(self, stream): '''Serve data from an IO stream over HTTP.''' diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py index 54111a7..c966916 100644 --- a/tests/integration/api_service_test.py +++ b/tests/integration/api_service_test.py @@ -376,6 +376,23 @@ class ServiceTest(BaseAPIIntegrationTest): assert 'TTY' in con_spec assert con_spec['TTY'] is True + @requires_api_version('1.25') + def test_create_service_with_tty_dict(self): + container_spec = { + 'Image': BUSYBOX, + 'Command': ['true'], + 'TTY': True + } + task_tmpl = docker.types.TaskTemplate(container_spec) + name = self.get_service_name() + svc_id = self.client.create_service(task_tmpl, name=name) + svc_info = self.client.inspect_service(svc_id) + assert 'TaskTemplate' in svc_info['Spec'] + assert 'ContainerSpec' in svc_info['Spec']['TaskTemplate'] + con_spec = svc_info['Spec']['TaskTemplate']['ContainerSpec'] + assert 'TTY' in con_spec + assert con_spec['TTY'] is True + def test_create_service_global_mode(self): container_spec = docker.types.ContainerSpec( BUSYBOX, ['echo', 'hello'] diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py index b76a88f..ce3349b 100644 --- a/tests/integration/models_containers_test.py +++ b/tests/integration/models_containers_test.py @@ -88,6 +88,24 @@ class ContainerCollectionTest(BaseIntegrationTest): assert 'Networks' in attrs['NetworkSettings'] assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name] + def test_run_with_none_driver(self): + client = docker.from_env(version=TEST_API_VERSION) + + out = client.containers.run( + "alpine", "echo hello", + log_config=dict(type='none') + ) + self.assertEqual(out, None) + + def test_run_with_json_file_driver(self): + client = docker.from_env(version=TEST_API_VERSION) + + out = client.containers.run( + "alpine", "echo hello", + log_config=dict(type='json-file') + ) + self.assertEqual(out, b'hello\n') + def test_get(self): client = docker.from_env(version=TEST_API_VERSION) container = client.containers.run("alpine", "sleep 300", detach=True) |