tests.unity.service: Make sure volumes order is preserved.

Signed-off-by: Antony MECHIN <antony.mechin@docker.com>
This commit is contained in:
Antony MECHIN 2018-09-24 16:57:49 +02:00
parent de1958c5ff
commit 39b0518850
2 changed files with 21 additions and 2 deletions

View File

@ -56,6 +56,7 @@ from .utils import json_hash
from .utils import parse_bytes
from .utils import parse_seconds_float
from .utils import truncate_id
from .utils import unique_everseen
log = logging.getLogger(__name__)
@ -940,8 +941,9 @@ class Service(object):
override_options['mounts'] = override_options.get('mounts') or []
override_options['mounts'].extend([build_mount(v) for v in secret_volumes])
# Remove possible duplicates (see e.g. https://github.com/docker/compose/issues/5885)
override_options['binds'] = list(set(binds))
# Remove possible duplicates (see e.g. https://github.com/docker/compose/issues/5885).
# unique_everseen preserves order. (see https://github.com/docker/compose/issues/6091).
override_options['binds'] = list(unique_everseen(binds))
return container_options, override_options
def _get_container_host_config(self, override_options, one_off=False):

View File

@ -1037,6 +1037,23 @@ class ServiceTest(unittest.TestCase):
assert len(override_opts['binds']) == 1
assert override_opts['binds'][0] == 'vol:/data:rw'
def test_volumes_order_is_preserved(self):
service = Service('foo', client=self.mock_client)
volumes = [
VolumeSpec.parse(cfg) for cfg in [
'/v{0}:/v{0}:rw'.format(i) for i in range(6)
]
]
ctnr_opts, override_opts = service._build_container_volume_options(
previous_container=None,
container_options={
'volumes': volumes,
'environment': {},
},
override_options={},
)
assert override_opts['binds'] == [vol.repr() for vol in volumes]
class TestServiceNetwork(unittest.TestCase):
def setUp(self):