Fix ServiceExtendsResolver same-file detection

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-02 19:23:39 -07:00 committed by Joffrey F
parent 0c4fc93895
commit 3ea8a20cfa
2 changed files with 37 additions and 1 deletions

View File

@ -571,7 +571,7 @@ class ServiceExtendsResolver(object):
config_path = self.get_extended_config_path(extends)
service_name = extends['service']
if config_path == self.service_config.filename:
if config_path == self.config_file.filename:
try:
service_config = self.config_file.get_service(service_name)
except KeyError:

View File

@ -702,6 +702,42 @@ class ConfigTest(unittest.TestCase):
]
self.assertEqual(service_sort(service_dicts), service_sort(expected))
def test_load_mixed_extends_resolution(self):
main_file = config.ConfigFile(
'main.yml', {
'version': '2.2',
'services': {
'prodweb': {
'extends': {
'service': 'web',
'file': 'base.yml'
},
'environment': {'PROD': 'true'},
},
},
}
)
tmpdir = pytest.ensuretemp('config_test')
self.addCleanup(tmpdir.remove)
tmpdir.join('base.yml').write("""
version: '2.2'
services:
base:
image: base
web:
extends: base
""")
details = config.ConfigDetails('.', [main_file])
with tmpdir.as_cwd():
service_dicts = config.load(details).services
assert service_dicts[0] == {
'name': 'prodweb',
'image': 'base',
'environment': {'PROD': 'true'},
}
def test_load_with_multiple_files_and_invalid_override(self):
base_file = config.ConfigFile(
'base.yaml',