Move service sorting to config package.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
da27f8e7e2
commit
81f0e72bd2
10 changed files with 91 additions and 92 deletions
|
|
@ -77,7 +77,7 @@ class ConfigTest(unittest.TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
def test_config_invalid_service_names(self):
|
||||
def test_load_config_invalid_service_names(self):
|
||||
for invalid_name in ['?not?allowed', ' ', '', '!', '/', '\xe2']:
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
config.load(build_config_details(
|
||||
|
|
@ -232,6 +232,27 @@ class ConfigTest(unittest.TestCase):
|
|||
assert "service 'bogus' doesn't have any configuration" in exc.exconly()
|
||||
assert "In file 'override.yaml'" in exc.exconly()
|
||||
|
||||
def test_load_sorts_in_dependency_order(self):
|
||||
config_details = build_config_details({
|
||||
'web': {
|
||||
'image': 'busybox:latest',
|
||||
'links': ['db'],
|
||||
},
|
||||
'db': {
|
||||
'image': 'busybox:latest',
|
||||
'volumes_from': ['volume:ro']
|
||||
},
|
||||
'volume': {
|
||||
'image': 'busybox:latest',
|
||||
'volumes': ['/tmp'],
|
||||
}
|
||||
})
|
||||
services = config.load(config_details)
|
||||
|
||||
assert services[0]['name'] == 'volume'
|
||||
assert services[1]['name'] == 'db'
|
||||
assert services[2]['name'] == 'web'
|
||||
|
||||
def test_config_valid_service_names(self):
|
||||
for valid_name in ['_', '-', '.__.', '_what-up.', 'what_.up----', 'whatup']:
|
||||
services = config.load(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from .. import unittest
|
||||
from compose.config.errors import DependencyError
|
||||
from compose.config.sort_services import sort_service_dicts
|
||||
from compose.config.types import VolumeFromSpec
|
||||
from compose.project import DependencyError
|
||||
from compose.project import sort_service_dicts
|
||||
from tests import unittest
|
||||
|
||||
|
||||
class SortServiceTest(unittest.TestCase):
|
||||
|
|
@ -34,29 +34,6 @@ class ProjectTest(unittest.TestCase):
|
|||
self.assertEqual(project.get_service('db').name, 'db')
|
||||
self.assertEqual(project.get_service('db').options['image'], 'busybox:latest')
|
||||
|
||||
def test_from_dict_sorts_in_dependency_order(self):
|
||||
project = Project.from_dicts('composetest', [
|
||||
{
|
||||
'name': 'web',
|
||||
'image': 'busybox:latest',
|
||||
'links': ['db'],
|
||||
},
|
||||
{
|
||||
'name': 'db',
|
||||
'image': 'busybox:latest',
|
||||
'volumes_from': [VolumeFromSpec('volume', 'ro')]
|
||||
},
|
||||
{
|
||||
'name': 'volume',
|
||||
'image': 'busybox:latest',
|
||||
'volumes': ['/tmp'],
|
||||
}
|
||||
], None)
|
||||
|
||||
self.assertEqual(project.services[0].name, 'volume')
|
||||
self.assertEqual(project.services[1].name, 'db')
|
||||
self.assertEqual(project.services[2].name, 'web')
|
||||
|
||||
def test_from_config(self):
|
||||
dicts = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ from compose.service import NoSuchImageError
|
|||
from compose.service import parse_repository_tag
|
||||
from compose.service import Service
|
||||
from compose.service import ServiceNet
|
||||
from compose.service import VolumeFromSpec
|
||||
from compose.service import VolumeSpec
|
||||
from compose.service import warn_on_masked_volume
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue