Skip to content

Commit

Permalink
Merge pull request #2 from tdesvenain/master
Browse files Browse the repository at this point in the history
Added unit tests in build_extra_hosts + fix
  • Loading branch information
sampwing committed Feb 27, 2015
2 parents c0abe43 + 3e6c7cd commit d88d668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fig/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ def build_extra_hosts(extra_hosts_config):
extra_hosts_dict.update(extra_hosts_line)
else:
# not already interpreted as a dict
extra_hosts_dict.update(extra_hosts_line.split(':'))
host, ip = extra_hosts_line.split(':')
extra_hosts_dict.update({host.strip(): ip.strip()})

return extra_hosts_dict

Expand Down
23 changes: 23 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from fig import Service
from fig.service import CannotBeScaledError
from fig.service import build_extra_hosts
from fig.container import Container
from docker.errors import APIError
from .testcases import DockerClientTestCase
Expand Down Expand Up @@ -106,6 +107,28 @@ def test_create_container_with_cpu_shares(self):
service.start_container(container)
self.assertEqual(container.inspect()['Config']['CpuShares'], 73)

def test_build_extra_hosts(self):
# string
self.assertEqual(build_extra_hosts("www.example.com: 192.168.0.17"),
{'www.example.com': '192.168.0.17'})

# list of strings
self.assertEqual(build_extra_hosts(
["www.example.com: 192.168.0.17"]),
{'www.example.com': '192.168.0.17'})
self.assertEqual(build_extra_hosts(
["www.example.com: 192.168.0.17",
"api.example.com: 192.168.0.18"]),
{'www.example.com': '192.168.0.17',
'api.example.com': '192.168.0.18'})
# list of dictionaries
self.assertEqual(build_extra_hosts(
[{'www.example.com': '192.168.0.17'},
{'api.example.com': '192.168.0.18'}
]),
{'www.example.com': '192.168.0.17',
'api.example.com': '192.168.0.18'})

def test_create_container_with_extra_hosts_list(self):
extra_hosts = ['docker:162.242.195.82', 'fig:50.31.209.229']
service = self.create_service('db', extra_hosts=extra_hosts)
Expand Down

0 comments on commit d88d668

Please sign in to comment.