Squashed commit of the following:

commit d3fbd3d630099dc0d34cb1a93b0a664f633a1c25
Author: zasca <gorstav@gmail.com>
Date:   Wed Oct 3 11:27:43 2018 +0600

    Fix typo in function name, path separator updated

commit bc3f03cd9a7702b3f2d96b18380d75e10f18def0
Author: zasca <gorstav@gmail.com>
Date:   Tue Oct 2 11:12:28 2018 +0600

    Fix endswith arg in the test

commit 602d2977b4e881850c99c7555bc284690a802815
Author: zasca <gorstav@gmail.com>
Date:   Mon Oct 1 12:24:17 2018 +0600

    Update test

commit 6cd7a4a2c411ddf9b8e7d91194c60fb2238db8d7
Author: zasca <gorstav@gmail.com>
Date:   Fri Sep 28 11:13:36 2018 +0600

    Fix last test

commit 0d37343433caceec18ea15babf924b5975b83c80
Author: zasca <gorstav@gmail.com>
Date:   Fri Sep 28 10:58:57 2018 +0600

    Unit test added

commit fc086e544677dd33bad798c773cb92600aaefc51
Author: zasca <gorstav@gmail.com>
Date:   Thu Sep 27 20:28:03 2018 +0600

    Improved expanding source paths of volumes

    defined with long syntax when paths starts with '~'

    Signed-off-by: Alexander <a.gorst.vinia@gmail.com>
This commit is contained in:
Alexander 2018-10-05 14:52:56 +06:00
parent c17274d014
commit 9d7202d122
2 changed files with 24 additions and 1 deletions

View File

@ -1281,7 +1281,7 @@ def resolve_volume_paths(working_dir, service_dict):
def resolve_volume_path(working_dir, volume):
if isinstance(volume, dict):
if volume.get('source', '').startswith('.') and volume['type'] == 'bind':
if volume.get('source', '').startswith(('.', '~')) and volume['type'] == 'bind':
volume['source'] = expand_path(working_dir, volume['source'])
return volume

View File

@ -1322,6 +1322,29 @@ class ConfigTest(unittest.TestCase):
assert mount.type == 'bind'
assert mount.source == expected_source
def test_load_bind_mount_relative_path_with_tilde(self):
base_file = config.ConfigFile(
'base.yaml', {
'version': '3.4',
'services': {
'web': {
'image': 'busybox:latest',
'volumes': [
{'type': 'bind', 'source': '~/web', 'target': '/web'},
],
},
},
},
)
details = config.ConfigDetails('.', [base_file])
config_data = config.load(details)
mount = config_data.services[0].get('volumes')[0]
assert mount.target == '/web'
assert mount.type == 'bind'
assert (not mount.source.startswith('~')
and mount.source.endswith('{}web'.format(os.path.sep)))
def test_config_invalid_ipam_config(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(