Fixes #2008 - re-use list_or_dict schema for all the types

At the same time, moves extra_hosts validation to the config module.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-11-13 18:58:24 -05:00
commit efec2aae6c
8 changed files with 90 additions and 88 deletions

View file

@ -32,7 +32,7 @@ def service_sort(services):
return sorted(services, key=itemgetter('name'))
def build_config_details(contents, working_dir, filename):
def build_config_details(contents, working_dir='working_dir', filename='filename.yml'):
return config.ConfigDetails(
working_dir,
[config.ConfigFile(filename, contents)])
@ -512,6 +512,29 @@ class ConfigTest(unittest.TestCase):
assert 'line 3, column 32' in exc.exconly()
def test_validate_extra_hosts_invalid(self):
with pytest.raises(ConfigurationError) as exc:
config.load(build_config_details({
'web': {
'image': 'alpine',
'extra_hosts': "www.example.com: 192.168.0.17",
}
}))
assert "'extra_hosts' contains an invalid type" in exc.exconly()
def test_validate_extra_hosts_invalid_list(self):
with pytest.raises(ConfigurationError) as exc:
config.load(build_config_details({
'web': {
'image': 'alpine',
'extra_hosts': [
{'www.example.com': '192.168.0.17'},
{'api.example.com': '192.168.0.18'}
],
}
}))
assert "which is an invalid type" in exc.exconly()
class InterpolationTest(unittest.TestCase):
@mock.patch.dict(os.environ)

View file

@ -0,0 +1,29 @@
from compose.config.types import parse_extra_hosts
def test_parse_extra_hosts_list():
expected = {'www.example.com': '192.168.0.17'}
assert parse_extra_hosts(["www.example.com:192.168.0.17"]) == expected
expected = {'www.example.com': '192.168.0.17'}
assert parse_extra_hosts(["www.example.com: 192.168.0.17"]) == expected
assert parse_extra_hosts([
"www.example.com: 192.168.0.17",
"static.example.com:192.168.0.19",
"api.example.com: 192.168.0.18"
]) == {
'www.example.com': '192.168.0.17',
'static.example.com': '192.168.0.19',
'api.example.com': '192.168.0.18'
}
def test_parse_extra_hosts_dict():
assert parse_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'
}