mirror of https://github.com/docker/compose.git
Fix oneOf validator parser to correctly process uniqueItems errors
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
1610af7e9f
commit
49b1ac57c3
|
@ -325,7 +325,6 @@ def _parse_oneof_validator(error):
|
|||
"""
|
||||
types = []
|
||||
for context in error.context:
|
||||
|
||||
if context.validator == 'oneOf':
|
||||
_, error_msg = _parse_oneof_validator(context)
|
||||
return path_string(context.path), error_msg
|
||||
|
@ -337,6 +336,13 @@ def _parse_oneof_validator(error):
|
|||
invalid_config_key = parse_key_from_error_msg(context)
|
||||
return (None, "contains unsupported option: '{}'".format(invalid_config_key))
|
||||
|
||||
if context.validator == 'uniqueItems':
|
||||
return (
|
||||
path_string(context.path) if context.path else None,
|
||||
"contains non-unique items, please remove duplicates from {}".format(
|
||||
context.instance),
|
||||
)
|
||||
|
||||
if context.path:
|
||||
return (
|
||||
path_string(context.path),
|
||||
|
@ -345,13 +351,6 @@ def _parse_oneof_validator(error):
|
|||
_parse_valid_types_from_validator(context.validator_value)),
|
||||
)
|
||||
|
||||
if context.validator == 'uniqueItems':
|
||||
return (
|
||||
None,
|
||||
"contains non unique items, please remove duplicates from {}".format(
|
||||
context.instance),
|
||||
)
|
||||
|
||||
if context.validator == 'type':
|
||||
types.append(context.validator_value)
|
||||
|
||||
|
|
|
@ -581,6 +581,20 @@ class ConfigTest(unittest.TestCase):
|
|||
|
||||
assert 'Invalid service name \'mong\\o\'' in excinfo.exconly()
|
||||
|
||||
def test_config_duplicate_cache_from_values_validation_error(self):
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
config.load(
|
||||
build_config_details({
|
||||
'version': '2.3',
|
||||
'services': {
|
||||
'test': {'build': {'context': '.', 'cache_from': ['a', 'b', 'a']}}
|
||||
}
|
||||
|
||||
})
|
||||
)
|
||||
|
||||
assert 'build.cache_from contains non-unique items' in exc.exconly()
|
||||
|
||||
def test_load_with_multiple_files_v1(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yaml',
|
||||
|
@ -2751,11 +2765,12 @@ class PortsTest(unittest.TestCase):
|
|||
|
||||
def check_config(self, cfg):
|
||||
config.load(
|
||||
build_config_details(
|
||||
{'web': dict(image='busybox', **cfg)},
|
||||
'working_dir',
|
||||
'filename.yml'
|
||||
)
|
||||
build_config_details({
|
||||
'version': '2.3',
|
||||
'services': {
|
||||
'web': dict(image='busybox', **cfg)
|
||||
},
|
||||
}, 'working_dir', 'filename.yml')
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue