diff options
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/container_test.py | 33 | ||||
| -rw-r--r-- | tests/unit/network_test.py | 12 | ||||
| -rw-r--r-- | tests/unit/utils_test.py | 10 |
3 files changed, 52 insertions, 3 deletions
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py index e1dda3e..c2b2573 100644 --- a/tests/unit/container_test.py +++ b/tests/unit/container_test.py @@ -7,6 +7,7 @@ import pytest import six from . import fake_api +from ..base import requires_api_version from .api_test import ( DockerClientTest, url_prefix, fake_request, DEFAULT_TIMEOUT_SECONDS, fake_inspect_container @@ -983,6 +984,38 @@ class CreateContainerTest(DockerClientTest): self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'}) + @requires_api_version('1.22') + def test_create_container_with_aliases(self): + self.client.create_container( + 'busybox', 'ls', + host_config=self.client.create_host_config( + network_mode='some-network', + ), + networking_config=self.client.create_networking_config({ + 'some-network': self.client.create_endpoint_config( + aliases=['foo', 'bar'], + ), + }), + ) + + args = fake_request.call_args + self.assertEqual(json.loads(args[1]['data']), + json.loads(''' + {"Tty": false, "Image": "busybox", + "Cmd": ["ls"], "AttachStdin": false, + "AttachStderr": true, + "AttachStdout": true, "OpenStdin": false, + "StdinOnce": false, + "NetworkDisabled": false, + "HostConfig": { + "NetworkMode": "some-network" + }, + "NetworkingConfig": { + "EndpointsConfig": { + "some-network": {"Aliases": ["foo", "bar"]} + } + }}''')) + class ContainerTest(DockerClientTest): def test_list_containers(self): diff --git a/tests/unit/network_test.py b/tests/unit/network_test.py index 7d2cc9a..fef3df3 100644 --- a/tests/unit/network_test.py +++ b/tests/unit/network_test.py @@ -147,7 +147,10 @@ class NetworkTest(DockerClientTest): with mock.patch('docker.Client.post', post): self.client.connect_container_to_network( - {'Id': container_id}, network_id) + {'Id': container_id}, + network_id, + aliases=['foo', 'bar'], + ) self.assertEqual( post.call_args[0][0], @@ -155,7 +158,12 @@ class NetworkTest(DockerClientTest): self.assertEqual( json.loads(post.call_args[1]['data']), - {'container': container_id}) + { + 'Container': container_id, + 'EndpointConfig': { + 'Aliases': ['foo', 'bar'], + }, + }) @base.requires_api_version('1.21') def test_disconnect_container_from_network(self): diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index d436de2..1ea13a9 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -18,8 +18,9 @@ from docker.utils import ( parse_repository_tag, parse_host, convert_filters, kwargs_from_env, create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file, exclude_paths, convert_volume_binds, decode_json_header, tar, - split_command, create_ipam_config, create_ipam_pool + split_command, create_ipam_config, create_ipam_pool, ) +from docker.utils.utils import create_endpoint_config from docker.utils.ports import build_port_bindings, split_port from .. import base @@ -69,6 +70,13 @@ class HostConfigTest(base.BaseTestCase): InvalidVersion, lambda: create_host_config(version='1.18.3', oom_kill_disable=True)) + def test_create_endpoint_config_with_aliases(self): + config = create_endpoint_config(version='1.22', aliases=['foo', 'bar']) + assert config == {'Aliases': ['foo', 'bar']} + + with pytest.raises(InvalidVersion): + create_endpoint_config(version='1.21', aliases=['foo', 'bar']) + class UlimitTest(base.BaseTestCase): def test_create_host_config_dict_ulimit(self): |
