Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce exposed_ports to string #1798

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions molecule/model/schema_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def pre_validate_base_schema(env, keep_string):
'type': 'list',
'schema': {
'type': 'string',
'coerce': 'exposed_ports'
}
},
'published_ports': {
Expand Down Expand Up @@ -970,6 +971,17 @@ def _validate_disallowed(self, disallowed, field, value):
msg = 'disallowed user provided config option'
self._error(field, msg)

def _normalize_coerce_exposed_ports(self, value):
"""Coerce ``exposed_ports`` values to string.

Not all types that can be specified by the user are acceptable and
therefore we cannot simply pass a ``'coerce': 'string'`` to the schema
definition.
"""
if type(value) == int:
return str(value)
return value

def _validate_molecule_env_var(self, molecule_env_var, field, value):
""" Readonly but with a custom error.

Expand Down
9 changes: 8 additions & 1 deletion test/unit/model/v2/test_platforms_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def test_platforms_unique_names(_config):
assert expected_validation_errors == schema_v2.validate(_config)


@pytest.mark.parametrize(
'_config', ['_model_platforms_docker_section_data'], indirect=True)
def test_platforms_docker_exposed_ports_coerced(_config):
_config['platforms'][0]['exposed_ports'] = [9904]
assert {} == schema_v2.validate(_config)


@pytest.fixture
def _model_platforms_docker_errors_section_data():
return {
Expand Down Expand Up @@ -171,7 +178,7 @@ def _model_platforms_docker_errors_section_data():
int(),
],
'exposed_ports': [
int(),
bool(),
],
'published_ports': [
int(),
Expand Down