Skip to content

Commit

Permalink
Unit test for skipping network disconnect.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <[email protected]>
  • Loading branch information
dnephin committed Apr 15, 2016
1 parent e1356e1 commit 625be1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/integration/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,11 @@ def test_project_up_networks(self):
'name': 'web',
'image': 'busybox:latest',
'command': 'top',
'networks': {'foo': None, 'bar': None, 'baz': None},
'networks': {
'foo': None,
'bar': None,
'baz': {'aliases': ['extra']},
},
}],
volumes={},
networks={
Expand All @@ -581,15 +585,23 @@ def test_project_up_networks(self):
config_data=config_data,
)
project.up()
self.assertEqual(len(project.containers()), 1)

containers = project.containers()
assert len(containers) == 1
container, = containers

for net_name in ['foo', 'bar', 'baz']:
full_net_name = 'composetest_{}'.format(net_name)
network_data = self.client.inspect_network(full_net_name)
self.assertEqual(network_data['Name'], full_net_name)
assert network_data['Name'] == full_net_name

aliases_key = 'NetworkSettings.Networks.{net}.Aliases'
assert 'web' in container.get(aliases_key.format(net='composetest_foo'))
assert 'web' in container.get(aliases_key.format(net='composetest_baz'))
assert 'extra' in container.get(aliases_key.format(net='composetest_baz'))

foo_data = self.client.inspect_network('composetest_foo')
self.assertEqual(foo_data['Driver'], 'bridge')
assert foo_data['Driver'] == 'bridge'

@v2_only()
def test_up_with_ipam_config(self):
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,35 @@ def test_only_log_warning_when_host_ports_clash(self, mock_log):
'for this service are created on a single host, the port will clash.'.format(name))


class TestServiceNetwork(object):

def test_connect_container_to_networks_short_aliase_exists(self):
mock_client = mock.create_autospec(docker.Client)
service = Service(
'db',
mock_client,
'myproject',
image='foo',
networks={'project_default': {}})
container = Container(
None,
{
'Id': 'abcdef',
'NetworkSettings': {
'Networks': {
'project_default': {
'Aliases': ['analias', 'abcdef'],
},
},
},
},
True)
service.connect_container_to_networks(container)

assert not mock_client.disconnect_container_from_network.call_count
assert not mock_client.connect_container_to_network.call_count


def sort_by_name(dictionary_list):
return sorted(dictionary_list, key=lambda k: k['name'])

Expand Down

0 comments on commit 625be1d

Please sign in to comment.