Require volumes_from a container to be explicit in V2 config.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
c3968a439f
commit
b76dc1e05e
11 changed files with 166 additions and 53 deletions
|
|
@ -19,7 +19,7 @@ from compose.const import IS_WINDOWS_PLATFORM
|
|||
from tests import mock
|
||||
from tests import unittest
|
||||
|
||||
DEFAULT_VERSION = 2
|
||||
DEFAULT_VERSION = V2 = 2
|
||||
V1 = 1
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class SortServiceTest(unittest.TestCase):
|
|||
},
|
||||
{
|
||||
'name': 'parent',
|
||||
'volumes_from': [VolumeFromSpec('child', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('child', 'rw', 'service')]
|
||||
},
|
||||
{
|
||||
'links': ['parent'],
|
||||
|
|
@ -120,7 +120,7 @@ class SortServiceTest(unittest.TestCase):
|
|||
},
|
||||
{
|
||||
'name': 'parent',
|
||||
'volumes_from': [VolumeFromSpec('child', 'ro')]
|
||||
'volumes_from': [VolumeFromSpec('child', 'ro', 'service')]
|
||||
},
|
||||
{
|
||||
'name': 'child'
|
||||
|
|
@ -145,7 +145,7 @@ class SortServiceTest(unittest.TestCase):
|
|||
},
|
||||
{
|
||||
'name': 'two',
|
||||
'volumes_from': [VolumeFromSpec('one', 'rw')]
|
||||
'volumes_from': [VolumeFromSpec('one', 'rw', 'service')]
|
||||
},
|
||||
{
|
||||
'name': 'one'
|
||||
|
|
|
|||
|
|
@ -5,8 +5,11 @@ import pytest
|
|||
|
||||
from compose.config.errors import ConfigurationError
|
||||
from compose.config.types import parse_extra_hosts
|
||||
from compose.config.types import VolumeFromSpec
|
||||
from compose.config.types import VolumeSpec
|
||||
from compose.const import IS_WINDOWS_PLATFORM
|
||||
from tests.unit.config.config_test import V1
|
||||
from tests.unit.config.config_test import V2
|
||||
|
||||
|
||||
def test_parse_extra_hosts_list():
|
||||
|
|
@ -67,3 +70,45 @@ class TestVolumeSpec(object):
|
|||
"/opt/shiny/config",
|
||||
"ro"
|
||||
)
|
||||
|
||||
|
||||
class TestVolumesFromSpec(object):
|
||||
|
||||
services = ['servicea', 'serviceb']
|
||||
|
||||
def test_parse_v1_from_service(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea', self.services, V1)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'rw', 'service')
|
||||
|
||||
def test_parse_v1_from_container(self):
|
||||
volume_from = VolumeFromSpec.parse('foo:ro', self.services, V1)
|
||||
assert volume_from == VolumeFromSpec('foo', 'ro', 'container')
|
||||
|
||||
def test_parse_v1_invalid(self):
|
||||
with pytest.raises(ConfigurationError):
|
||||
VolumeFromSpec.parse('unknown:format:ro', self.services, V1)
|
||||
|
||||
def test_parse_v2_from_service(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'rw', 'service')
|
||||
|
||||
def test_parse_v2_from_service_with_mode(self):
|
||||
volume_from = VolumeFromSpec.parse('servicea:ro', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('servicea', 'ro', 'service')
|
||||
|
||||
def test_parse_v2_from_container(self):
|
||||
volume_from = VolumeFromSpec.parse('container:foo', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('foo', 'rw', 'container')
|
||||
|
||||
def test_parse_v2_from_container_with_mode(self):
|
||||
volume_from = VolumeFromSpec.parse('container:foo:ro', self.services, V2)
|
||||
assert volume_from == VolumeFromSpec('foo', 'ro', 'container')
|
||||
|
||||
def test_parse_v2_invalid_type(self):
|
||||
with pytest.raises(ConfigurationError) as exc:
|
||||
VolumeFromSpec.parse('bogus:foo:ro', self.services, V2)
|
||||
assert "Unknown volumes_from type 'bogus'" in exc.exconly()
|
||||
|
||||
def test_parse_v2_invalid(self):
|
||||
with pytest.raises(ConfigurationError):
|
||||
VolumeFromSpec.parse('unknown:format:ro', self.services, V2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue