Fix when pyyaml has interpreted line as a dictionary
Added unit tests in build_extra_hosts + fix Signed-off-by: CJ <lim@chernjie.com>
This commit is contained in:
parent
fb81c37ca6
commit
8098b65576
2 changed files with 37 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import mock
|
|||
|
||||
from compose import Service
|
||||
from compose.service import CannotBeScaledError
|
||||
from compose.service import build_extra_hosts
|
||||
from compose.container import Container
|
||||
from docker.errors import APIError
|
||||
from .testcases import DockerClientTestCase
|
||||
|
|
@ -107,6 +108,28 @@ class ServiceTest(DockerClientTestCase):
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue