|
|
@@ -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)
|