mirror of https://github.com/docker/compose.git
Tag v2-only tests
- Don't run them against Engine < 1.10 - Set the API version appropriately for the Engine version, so all tests use API version 1.22 against Engine 1.10 Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
abd031cb3d
commit
406b6b28f4
|
@ -20,6 +20,7 @@ from compose.container import Container
|
|||
from tests.integration.testcases import DockerClientTestCase
|
||||
from tests.integration.testcases import get_links
|
||||
from tests.integration.testcases import pull_busybox
|
||||
from tests.integration.testcases import v2_only
|
||||
|
||||
|
||||
ProcessResult = namedtuple('ProcessResult', 'stdout stderr')
|
||||
|
@ -388,6 +389,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
assert 'simple_1 | simple' in result.stdout
|
||||
assert 'another_1 | another' in result.stdout
|
||||
|
||||
@v2_only()
|
||||
def test_up(self):
|
||||
self.base_dir = 'tests/fixtures/v2-simple'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
@ -413,6 +415,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
for service in services:
|
||||
assert self.lookup(container, service.name)
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_networks(self):
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
@ -448,6 +451,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
# app can see db
|
||||
assert self.lookup(app_container, "db")
|
||||
|
||||
@v2_only()
|
||||
def test_up_missing_network(self):
|
||||
self.base_dir = 'tests/fixtures/networks'
|
||||
|
||||
|
@ -457,6 +461,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
assert 'Service "web" uses an undefined network "foo"' in result.stderr
|
||||
|
||||
@v2_only()
|
||||
def test_up_predefined_networks(self):
|
||||
filename = 'predefined-networks.yml'
|
||||
|
||||
|
@ -476,6 +481,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
assert list(container.get('NetworkSettings.Networks')) == [name]
|
||||
assert container.get('HostConfig.NetworkMode') == name
|
||||
|
||||
@v2_only()
|
||||
def test_up_external_networks(self):
|
||||
filename = 'external-networks.yml'
|
||||
|
||||
|
@ -499,6 +505,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
container = self.project.containers()[0]
|
||||
assert sorted(list(container.get('NetworkSettings.Networks'))) == sorted(network_names)
|
||||
|
||||
@v2_only()
|
||||
def test_up_no_services(self):
|
||||
self.base_dir = 'tests/fixtures/no-services'
|
||||
self.dispatch(['up', '-d'], None)
|
||||
|
@ -513,6 +520,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
for name in ['bar', 'foo']
|
||||
]
|
||||
|
||||
@v2_only()
|
||||
def test_up_with_links_is_invalid(self):
|
||||
self.base_dir = 'tests/fixtures/v2-simple'
|
||||
|
||||
|
@ -853,6 +861,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
container, = service.containers(stopped=True, one_off=True)
|
||||
self.assertEqual(container.name, name)
|
||||
|
||||
@v2_only()
|
||||
def test_run_with_networking(self):
|
||||
self.base_dir = 'tests/fixtures/v2-simple'
|
||||
self.dispatch(['run', 'simple', 'true'], None)
|
||||
|
|
|
@ -14,6 +14,7 @@ from compose.const import LABEL_PROJECT
|
|||
from compose.container import Container
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
from tests.integration.testcases import v2_only
|
||||
|
||||
|
||||
def build_service_dicts(service_config):
|
||||
|
@ -482,6 +483,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
service = project.get_service('web')
|
||||
self.assertEqual(len(service.containers()), 1)
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_networks(self):
|
||||
config_data = config.Config(
|
||||
version=2,
|
||||
|
@ -514,6 +516,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
foo_data = self.client.inspect_network('composetest_foo')
|
||||
self.assertEqual(foo_data['Driver'], 'bridge')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_volumes(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
@ -539,6 +542,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_logging_with_multiple_files(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yml',
|
||||
|
@ -590,6 +594,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertTrue(log_config)
|
||||
self.assertEqual(log_config.get('Type'), 'none')
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
@ -614,6 +619,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_implicit_volume_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
@ -638,6 +644,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_invalid_volume_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
||||
|
@ -659,6 +666,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
with self.assertRaises(config.ConfigurationError):
|
||||
project.initialize_volumes()
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_updated_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
@ -696,6 +704,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
vol_name
|
||||
) in str(e.exception)
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_external_volumes(self):
|
||||
# Use composetest_ prefix so it gets garbage-collected in tearDown()
|
||||
vol_name = 'composetest_{0:x}'.format(random.getrandbits(32))
|
||||
|
@ -722,6 +731,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
with self.assertRaises(NotFound):
|
||||
self.client.inspect_volume(full_vol_name)
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_inexistent_external_volume(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import os
|
||||
|
||||
from docker.utils import version_lt
|
||||
from pytest import skip
|
||||
|
||||
from .. import unittest
|
||||
from compose.cli.docker_client import docker_client
|
||||
from compose.config.config import resolve_environment
|
||||
from compose.const import API_VERSIONS
|
||||
from compose.const import LABEL_PROJECT
|
||||
from compose.progress_stream import stream_output
|
||||
from compose.service import Service
|
||||
|
@ -26,10 +30,35 @@ def get_links(container):
|
|||
return [format_link(link) for link in links]
|
||||
|
||||
|
||||
def engine_version_too_low_for_v2():
|
||||
if 'DOCKER_VERSION' not in os.environ:
|
||||
return False
|
||||
version = os.environ['DOCKER_VERSION'].partition('-')[0]
|
||||
return version_lt(version, '1.10')
|
||||
|
||||
|
||||
def v2_only():
|
||||
def decorator(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if engine_version_too_low_for_v2():
|
||||
skip("Engine version is too low")
|
||||
return
|
||||
return f(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class DockerClientTestCase(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.client = docker_client()
|
||||
if engine_version_too_low_for_v2():
|
||||
version = API_VERSIONS[1]
|
||||
else:
|
||||
version = API_VERSIONS[2]
|
||||
|
||||
cls.client = docker_client(version)
|
||||
|
||||
def tearDown(self):
|
||||
for c in self.client.containers(
|
||||
|
|
Loading…
Reference in New Issue