Validate that each section of the config is a mapping before running interpolation.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-02-16 17:30:23 -05:00
commit 7d22809ef4
5 changed files with 91 additions and 37 deletions

View file

@ -231,7 +231,7 @@ class ConfigTest(unittest.TestCase):
assert volumes['simple'] == {}
assert volumes['other'] == {}
def test_volume_numeric_driver_opt(self):
def test_named_volume_numeric_driver_opt(self):
config_details = build_config_details({
'version': '2',
'services': {
@ -258,6 +258,30 @@ class ConfigTest(unittest.TestCase):
config.load(config_details)
assert 'driver_opts.size contains an invalid type' in exc.exconly()
def test_named_volume_invalid_type_list(self):
config_details = build_config_details({
'version': '2',
'services': {
'simple': {'image': 'busybox'}
},
'volumes': []
})
with pytest.raises(ConfigurationError) as exc:
config.load(config_details)
assert "volume must be a mapping, not 'array'" in exc.exconly()
def test_networks_invalid_type_list(self):
config_details = build_config_details({
'version': '2',
'services': {
'simple': {'image': 'busybox'}
},
'networks': []
})
with pytest.raises(ConfigurationError) as exc:
config.load(config_details)
assert "network must be a mapping, not 'array'" in exc.exconly()
def test_load_service_with_name_version(self):
with mock.patch('compose.config.config.log') as mock_logging:
config_data = config.load(
@ -368,7 +392,7 @@ class ConfigTest(unittest.TestCase):
'filename.yml')
with pytest.raises(ConfigurationError) as exc:
config.load(config_details)
error_msg = "service 'web' doesn't have any configuration options"
error_msg = "service 'web' is the wrong type"
assert error_msg in exc.exconly()
def test_config_integer_service_name_raise_validation_error(self):
@ -381,7 +405,7 @@ class ConfigTest(unittest.TestCase):
)
)
assert "In file 'filename.yml' service name: 1 needs to be a string, eg '1'" \
assert "In file 'filename.yml' service name 1 needs to be a string, eg '1'" \
in excinfo.exconly()
def test_config_integer_service_name_raise_validation_error_v2(self):
@ -397,7 +421,7 @@ class ConfigTest(unittest.TestCase):
)
)
assert "In file 'filename.yml' service name: 1 needs to be a string, eg '1'" \
assert "In file 'filename.yml' service name 1 needs to be a string, eg '1'" \
in excinfo.exconly()
def test_load_with_multiple_files_v1(self):
@ -532,7 +556,7 @@ class ConfigTest(unittest.TestCase):
with pytest.raises(ConfigurationError) as exc:
config.load(details)
assert "service 'bogus' doesn't have any configuration" in exc.exconly()
assert "service 'bogus' is the wrong type" in exc.exconly()
assert "In file 'override.yaml'" in exc.exconly()
def test_load_sorts_in_dependency_order(self):