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
432dffc710
commit
3654f3ac48
|
@ -325,7 +325,6 @@ def _parse_oneof_validator(error):
|
||||||
"""
|
"""
|
||||||
types = []
|
types = []
|
||||||
for context in error.context:
|
for context in error.context:
|
||||||
|
|
||||||
if context.validator == 'oneOf':
|
if context.validator == 'oneOf':
|
||||||
_, error_msg = _parse_oneof_validator(context)
|
_, error_msg = _parse_oneof_validator(context)
|
||||||
return path_string(context.path), error_msg
|
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)
|
invalid_config_key = parse_key_from_error_msg(context)
|
||||||
return (None, "contains unsupported option: '{}'".format(invalid_config_key))
|
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:
|
if context.path:
|
||||||
return (
|
return (
|
||||||
path_string(context.path),
|
path_string(context.path),
|
||||||
|
@ -345,13 +351,6 @@ def _parse_oneof_validator(error):
|
||||||
_parse_valid_types_from_validator(context.validator_value)),
|
_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':
|
if context.validator == 'type':
|
||||||
types.append(context.validator_value)
|
types.append(context.validator_value)
|
||||||
|
|
||||||
|
|
|
@ -581,6 +581,20 @@ class ConfigTest(unittest.TestCase):
|
||||||
|
|
||||||
assert 'Invalid service name \'mong\\o\'' in excinfo.exconly()
|
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):
|
def test_load_with_multiple_files_v1(self):
|
||||||
base_file = config.ConfigFile(
|
base_file = config.ConfigFile(
|
||||||
'base.yaml',
|
'base.yaml',
|
||||||
|
@ -2751,11 +2765,12 @@ class PortsTest(unittest.TestCase):
|
||||||
|
|
||||||
def check_config(self, cfg):
|
def check_config(self, cfg):
|
||||||
config.load(
|
config.load(
|
||||||
build_config_details(
|
build_config_details({
|
||||||
{'web': dict(image='busybox', **cfg)},
|
'version': '2.3',
|
||||||
'working_dir',
|
'services': {
|
||||||
'filename.yml'
|
'web': dict(image='busybox', **cfg)
|
||||||
)
|
},
|
||||||
|
}, 'working_dir', 'filename.yml')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue