Merge pull request #2349 from dnephin/validate_all_files

Validate all files before merging them
This commit is contained in:
Daniel Nephin 2015-11-11 15:27:47 -05:00
commit 76f3c9c739
9 changed files with 113 additions and 92 deletions

View file

@ -5,7 +5,7 @@ bar:
web:
extends:
file: circle-2.yml
service: web
service: other
baz:
image: busybox
quux:

View file

@ -2,7 +2,7 @@ foo:
image: busybox
bar:
image: busybox
web:
other:
extends:
file: circle-1.yml
service: web

View file

@ -842,7 +842,13 @@ class ServiceTest(DockerClientTestCase):
environment=['ONE=1', 'TWO=2', 'THREE=3'],
env_file=['tests/fixtures/env/one.env', 'tests/fixtures/env/two.env'])
env = create_and_start_container(service).environment
for k, v in {'ONE': '1', 'TWO': '2', 'THREE': '3', 'FOO': 'baz', 'DOO': 'dah'}.items():
for k, v in {
'ONE': '1',
'TWO': '2',
'THREE': '3',
'FOO': 'baz',
'DOO': 'dah'
}.items():
self.assertEqual(env[k], v)
@mock.patch.dict(os.environ)
@ -850,9 +856,22 @@ class ServiceTest(DockerClientTestCase):
os.environ['FILE_DEF'] = 'E1'
os.environ['FILE_DEF_EMPTY'] = 'E2'
os.environ['ENV_DEF'] = 'E3'
service = self.create_service('web', environment={'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': None, 'NO_DEF': None})
service = self.create_service(
'web',
environment={
'FILE_DEF': 'F1',
'FILE_DEF_EMPTY': '',
'ENV_DEF': None,
'NO_DEF': None
}
)
env = create_and_start_container(service).environment
for k, v in {'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''}.items():
for k, v in {
'FILE_DEF': 'F1',
'FILE_DEF_EMPTY': '',
'ENV_DEF': 'E3',
'NO_DEF': ''
}.items():
self.assertEqual(env[k], v)
def test_with_high_enough_api_version_we_get_default_network_mode(self):

View file

@ -7,7 +7,8 @@ from pytest import skip
from .. import unittest
from compose.cli.docker_client import docker_client
from compose.config.config import ServiceLoader
from compose.config.config import process_service
from compose.config.config import resolve_environment
from compose.const import LABEL_PROJECT
from compose.progress_stream import stream_output
from compose.service import Service
@ -42,23 +43,15 @@ class DockerClientTestCase(unittest.TestCase):
if 'command' not in kwargs:
kwargs['command'] = ["top"]
workaround_options = {}
for option in ['links', 'volumes_from', 'net']:
if option in kwargs:
workaround_options[option] = kwargs.pop(option, None)
options = ServiceLoader(
working_dir='.',
filename=None,
service_name=name,
service_dict=kwargs
).make_service_dict()
options.update(workaround_options)
# TODO: remove this once #2299 is fixed
kwargs['name'] = name
options = process_service('.', kwargs)
options['environment'] = resolve_environment('.', kwargs)
labels = options.setdefault('labels', {})
labels['com.docker.compose.test-name'] = self.id()
return Service(project='composetest', client=self.client, **options)
return Service(client=self.client, project='composetest', **options)
def check_build(self, *args, **kwargs):
kwargs.setdefault('rm', True)

View file

@ -18,13 +18,14 @@ from tests import unittest
def make_service_dict(name, service_dict, working_dir, filename=None):
"""
Test helper function to construct a ServiceLoader
Test helper function to construct a ServiceExtendsResolver
"""
return config.ServiceLoader(
resolver = config.ServiceExtendsResolver(
working_dir=working_dir,
filename=filename,
service_name=name,
service_dict=service_dict).make_service_dict()
service_dict=service_dict)
return config.process_service(working_dir, resolver.run())
def service_sort(services):
@ -195,6 +196,19 @@ class ConfigTest(unittest.TestCase):
]
self.assertEqual(service_sort(service_dicts), service_sort(expected))
def test_load_with_multiple_files_and_invalid_override(self):
base_file = config.ConfigFile(
'base.yaml',
{'web': {'image': 'example/web'}})
override_file = config.ConfigFile(
'override.yaml',
{'bogus': 'thing'})
details = config.ConfigDetails('.', [base_file, override_file])
with pytest.raises(ConfigurationError) as exc:
config.load(details)
assert 'Service "bogus" doesn\'t have any configuration' in exc.exconly()
def test_config_valid_service_names(self):
for valid_name in ['_', '-', '.__.', '_what-up.', 'what_.up----', 'whatup']:
config.load(
@ -1066,18 +1080,19 @@ class ExtendsTest(unittest.TestCase):
]))
def test_circular(self):
try:
with pytest.raises(config.CircularReference) as exc:
load_from_filename('tests/fixtures/extends/circle-1.yml')
raise Exception("Expected config.CircularReference to be raised")
except config.CircularReference as e:
self.assertEqual(
[(os.path.basename(filename), service_name) for (filename, service_name) in e.trail],
[
('circle-1.yml', 'web'),
('circle-2.yml', 'web'),
('circle-1.yml', 'web'),
],
)
path = [
(os.path.basename(filename), service_name)
for (filename, service_name) in exc.value.trail
]
expected = [
('circle-1.yml', 'web'),
('circle-2.yml', 'other'),
('circle-1.yml', 'web'),
]
self.assertEqual(path, expected)
def test_extends_validation_empty_dictionary(self):
with self.assertRaisesRegexp(ConfigurationError, 'service'):