From c7b71422c0bea8ce19b8f28e426fe4ea597eb83c Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 6 Jan 2016 13:30:40 -0500 Subject: [PATCH] Fix extends with multiple files. Signed-off-by: Daniel Nephin --- compose/config/config.py | 2 ++ tests/unit/config/config_test.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/compose/config/config.py b/compose/config/config.py index 195665b51..9e62ef1c7 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -422,6 +422,8 @@ def merge_service_dicts_from_files(base, override): new_service = merge_service_dicts(base, override) if 'extends' in override: new_service['extends'] = override['extends'] + elif 'extends' in base: + new_service['extends'] = base['extends'] return new_service diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index e975cb9d8..97a0838f8 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -552,6 +552,37 @@ class ConfigTest(unittest.TestCase): } ] + def test_merge_service_dicts_from_files_with_extends_in_base(self): + base = { + 'volumes': ['.:/app'], + 'extends': {'service': 'app'} + } + override = { + 'image': 'alpine:edge', + } + actual = config.merge_service_dicts_from_files(base, override) + assert actual == { + 'image': 'alpine:edge', + 'volumes': ['.:/app'], + 'extends': {'service': 'app'} + } + + def test_merge_service_dicts_from_files_with_extends_in_override(self): + base = { + 'volumes': ['.:/app'], + 'extends': {'service': 'app'} + } + override = { + 'image': 'alpine:edge', + 'extends': {'service': 'foo'} + } + actual = config.merge_service_dicts_from_files(base, override) + assert actual == { + 'image': 'alpine:edge', + 'volumes': ['.:/app'], + 'extends': {'service': 'foo'} + } + class PortsTest(unittest.TestCase): INVALID_PORTS_TYPES = [