mirror of
https://github.com/docker/compose.git
synced 2025-06-27 00:44:26 +02:00
Merge pull request #4529 from shin-/3528-invalid-service-name
Detect the service that causes the invalid service name error
This commit is contained in:
commit
7e8dcc847b
@ -211,9 +211,12 @@ def handle_error_for_schema_with_id(error, path):
|
|||||||
|
|
||||||
if is_service_dict_schema(schema_id) and error.validator == 'additionalProperties':
|
if is_service_dict_schema(schema_id) and error.validator == 'additionalProperties':
|
||||||
return "Invalid service name '{}' - only {} characters are allowed".format(
|
return "Invalid service name '{}' - only {} characters are allowed".format(
|
||||||
# The service_name is the key to the json object
|
# The service_name is one of the keys in the json object
|
||||||
list(error.instance)[0],
|
[i for i in list(error.instance) if not i or any(filter(
|
||||||
VALID_NAME_CHARS)
|
lambda c: not re.match(VALID_NAME_CHARS, c), i
|
||||||
|
))][0],
|
||||||
|
VALID_NAME_CHARS
|
||||||
|
)
|
||||||
|
|
||||||
if error.validator == 'additionalProperties':
|
if error.validator == 'additionalProperties':
|
||||||
if schema_id == '#/definitions/service':
|
if schema_id == '#/definitions/service':
|
||||||
|
@ -554,6 +554,20 @@ class ConfigTest(unittest.TestCase):
|
|||||||
excinfo.exconly()
|
excinfo.exconly()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_config_invalid_service_name_raise_validation_error(self):
|
||||||
|
with pytest.raises(ConfigurationError) as excinfo:
|
||||||
|
config.load(
|
||||||
|
build_config_details({
|
||||||
|
'version': '2',
|
||||||
|
'services': {
|
||||||
|
'test_app': {'build': '.'},
|
||||||
|
'mong\\o': {'image': 'mongo'},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
assert 'Invalid service name \'mong\\o\'' in excinfo.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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user