mirror of https://github.com/docker/compose.git
Fix volume merging when there's no explicit host path
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
276e43ca6b
commit
35c6e0314c
|
@ -324,15 +324,24 @@ def dict_from_volumes(volumes):
|
|||
return {}
|
||||
|
||||
|
||||
def split_volume(volume):
|
||||
if ':' in volume:
|
||||
return reversed(volume.split(':', 1))
|
||||
else:
|
||||
return (volume, None)
|
||||
|
||||
|
||||
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):
|
||||
|
|
|
@ -40,26 +40,44 @@ class ConfigTest(unittest.TestCase):
|
|||
|
||||
|
||||
class MergeTest(unittest.TestCase):
|
||||
def test_merge_volumes(self):
|
||||
def test_merge_volumes_empty(self):
|
||||
service_dict = config.merge_service_dicts({}, {})
|
||||
self.assertNotIn('volumes', service_dict)
|
||||
|
||||
service_dict = config.merge_service_dicts({
|
||||
'volumes': ['/foo:/data'],
|
||||
}, {})
|
||||
self.assertEqual(service_dict['volumes'], ['/foo:/data'])
|
||||
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']))
|
||||
|
||||
service_dict = config.merge_service_dicts({}, {
|
||||
'volumes': ['/bar:/data'],
|
||||
})
|
||||
self.assertEqual(service_dict['volumes'], ['/bar:/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']))
|
||||
|
||||
service_dict = config.merge_service_dicts({
|
||||
'volumes': ['/foo:/data'],
|
||||
}, {
|
||||
'volumes': ['/bar:/data'],
|
||||
})
|
||||
self.assertEqual(service_dict['volumes'], ['/bar:/data'])
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue