mirror of https://github.com/docker/compose.git
Merge pull request #1160 from aanand/fix-volume-merging
Fix volume merging
This commit is contained in:
commit
1f06070f12
|
@ -318,18 +318,30 @@ def merge_volumes(base, override):
|
|||
|
||||
|
||||
def dict_from_volumes(volumes):
|
||||
return dict(split_volume(v) for v in volumes)
|
||||
|
||||
|
||||
def split_volume(volume):
|
||||
if ':' in volume:
|
||||
return reversed(volume.split(':', 1))
|
||||
if volumes:
|
||||
return dict(split_volume(v) for v in volumes)
|
||||
else:
|
||||
return (volume, None)
|
||||
return {}
|
||||
|
||||
|
||||
def volumes_from_dict(d):
|
||||
return ["%s:%s" % (host_path, container_path) for (container_path, host_path) in d.items()]
|
||||
return [join_volume(v) for v in d.items()]
|
||||
|
||||
|
||||
def split_volume(string):
|
||||
if ':' in string:
|
||||
(host, container) = string.split(':', 1)
|
||||
return (container, host)
|
||||
else:
|
||||
return (string, None)
|
||||
|
||||
|
||||
def join_volume(pair):
|
||||
(container, host) = pair
|
||||
if host is None:
|
||||
return container
|
||||
else:
|
||||
return ":".join((host, container))
|
||||
|
||||
|
||||
def expand_path(working_dir, path):
|
||||
|
|
|
@ -39,6 +39,47 @@ class ConfigTest(unittest.TestCase):
|
|||
config.make_service_dict('foo', {'ports': ['8000']})
|
||||
|
||||
|
||||
class MergeTest(unittest.TestCase):
|
||||
def test_merge_volumes_empty(self):
|
||||
service_dict = config.merge_service_dicts({}, {})
|
||||
self.assertNotIn('volumes', service_dict)
|
||||
|
||||
def test_merge_volumes_no_override(self):
|
||||
service_dict = config.merge_service_dicts(
|
||||
{'volumes': ['/foo:/code', '/data']},
|
||||
{},
|
||||
)
|
||||
self.assertEqual(set(service_dict['volumes']), set(['/foo:/code', '/data']))
|
||||
|
||||
def test_merge_volumes_no_base(self):
|
||||
service_dict = config.merge_service_dicts(
|
||||
{},
|
||||
{'volumes': ['/bar:/code']},
|
||||
)
|
||||
self.assertEqual(set(service_dict['volumes']), set(['/bar:/code']))
|
||||
|
||||
def test_merge_volumes_override_explicit_path(self):
|
||||
service_dict = config.merge_service_dicts(
|
||||
{'volumes': ['/foo:/code', '/data']},
|
||||
{'volumes': ['/bar:/code']},
|
||||
)
|
||||
self.assertEqual(set(service_dict['volumes']), set(['/bar:/code', '/data']))
|
||||
|
||||
def test_merge_volumes_add_explicit_path(self):
|
||||
service_dict = config.merge_service_dicts(
|
||||
{'volumes': ['/foo:/code', '/data']},
|
||||
{'volumes': ['/bar:/code', '/quux:/data']},
|
||||
)
|
||||
self.assertEqual(set(service_dict['volumes']), set(['/bar:/code', '/quux:/data']))
|
||||
|
||||
def test_merge_volumes_remove_explicit_path(self):
|
||||
service_dict = config.merge_service_dicts(
|
||||
{'volumes': ['/foo:/code', '/quux:/data']},
|
||||
{'volumes': ['/bar:/code', '/data']},
|
||||
)
|
||||
self.assertEqual(set(service_dict['volumes']), set(['/bar:/code', '/data']))
|
||||
|
||||
|
||||
class EnvTest(unittest.TestCase):
|
||||
def test_parse_environment_as_list(self):
|
||||
environment =[
|
||||
|
|
Loading…
Reference in New Issue