Skip to content

Commit

Permalink
Coerce exposed_ports to string
Browse files Browse the repository at this point in the history
  • Loading branch information
decentral1se committed Mar 4, 2019
1 parent 97b3ae9 commit 88256ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 88256ba

Please sign in to comment.