mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
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 {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def split_volume(volume):
|
|
||||||
if ':' in volume:
|
|
||||||
return reversed(volume.split(':', 1))
|
|
||||||
else:
|
|
||||||
return (volume, None)
|
|
||||||
|
|
||||||
|
|
||||||
def volumes_from_dict(d):
|
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):
|
def expand_path(working_dir, path):
|
||||||
|
@ -40,26 +40,44 @@ class ConfigTest(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class MergeTest(unittest.TestCase):
|
class MergeTest(unittest.TestCase):
|
||||||
def test_merge_volumes(self):
|
def test_merge_volumes_empty(self):
|
||||||
service_dict = config.merge_service_dicts({}, {})
|
service_dict = config.merge_service_dicts({}, {})
|
||||||
self.assertNotIn('volumes', service_dict)
|
self.assertNotIn('volumes', service_dict)
|
||||||
|
|
||||||
service_dict = config.merge_service_dicts({
|
def test_merge_volumes_no_override(self):
|
||||||
'volumes': ['/foo:/data'],
|
service_dict = config.merge_service_dicts(
|
||||||
}, {})
|
{'volumes': ['/foo:/code', '/data']},
|
||||||
self.assertEqual(service_dict['volumes'], ['/foo:/data'])
|
{},
|
||||||
|
)
|
||||||
|
self.assertEqual(set(service_dict['volumes']), set(['/foo:/code', '/data']))
|
||||||
|
|
||||||
service_dict = config.merge_service_dicts({}, {
|
def test_merge_volumes_no_base(self):
|
||||||
'volumes': ['/bar:/data'],
|
service_dict = config.merge_service_dicts(
|
||||||
})
|
{},
|
||||||
self.assertEqual(service_dict['volumes'], ['/bar:/data'])
|
{'volumes': ['/bar:/code']},
|
||||||
|
)
|
||||||
|
self.assertEqual(set(service_dict['volumes']), set(['/bar:/code']))
|
||||||
|
|
||||||
service_dict = config.merge_service_dicts({
|
def test_merge_volumes_override_explicit_path(self):
|
||||||
'volumes': ['/foo:/data'],
|
service_dict = config.merge_service_dicts(
|
||||||
}, {
|
{'volumes': ['/foo:/code', '/data']},
|
||||||
'volumes': ['/bar:/data'],
|
{'volumes': ['/bar:/code']},
|
||||||
})
|
)
|
||||||
self.assertEqual(service_dict['volumes'], ['/bar:/data'])
|
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):
|
class EnvTest(unittest.TestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user