Support variable interpolation for volumes and networks sections.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
3750811eed
commit
79df2ebe1b
4 changed files with 104 additions and 33 deletions
|
|
@ -686,8 +686,8 @@ class ConfigTest(unittest.TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
self.assertTrue(mock_logging.warn.called)
|
||||
self.assertTrue(expected_warning_msg in mock_logging.warn.call_args[0][0])
|
||||
assert mock_logging.warn.called
|
||||
assert expected_warning_msg in mock_logging.warn.call_args[0][0]
|
||||
|
||||
def test_config_valid_environment_dict_key_contains_dashes(self):
|
||||
services = config.load(
|
||||
|
|
@ -1664,15 +1664,13 @@ class ExtendsTest(unittest.TestCase):
|
|||
load_from_filename('tests/fixtures/extends/invalid-net.yml')
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_valid_interpolation_in_extended_service(self):
|
||||
os.environ.update(
|
||||
HOSTNAME_VALUE="penguin",
|
||||
)
|
||||
def test_load_config_runs_interpolation_in_extended_service(self):
|
||||
os.environ.update(HOSTNAME_VALUE="penguin")
|
||||
expected_interpolated_value = "host-penguin"
|
||||
|
||||
service_dicts = load_from_filename('tests/fixtures/extends/valid-interpolation.yml')
|
||||
service_dicts = load_from_filename(
|
||||
'tests/fixtures/extends/valid-interpolation.yml')
|
||||
for service in service_dicts:
|
||||
self.assertTrue(service['hostname'], expected_interpolated_value)
|
||||
assert service['hostname'] == expected_interpolated_value
|
||||
|
||||
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
|
||||
def test_volume_path(self):
|
||||
|
|
|
|||
69
tests/unit/config/interpolation_test.py
Normal file
69
tests/unit/config/interpolation_test.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from compose.config.interpolation import interpolate_environment_variables
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def mock_env():
|
||||
with mock.patch.dict(os.environ):
|
||||
os.environ['USER'] = 'jenny'
|
||||
os.environ['FOO'] = 'bar'
|
||||
yield
|
||||
|
||||
|
||||
def test_interpolate_environment_variables_in_services(mock_env):
|
||||
services = {
|
||||
'servivea': {
|
||||
'image': 'example:${USER}',
|
||||
'volumes': ['$FOO:/target'],
|
||||
'logging': {
|
||||
'driver': '${FOO}',
|
||||
'options': {
|
||||
'user': '$USER',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expected = {
|
||||
'servivea': {
|
||||
'image': 'example:jenny',
|
||||
'volumes': ['bar:/target'],
|
||||
'logging': {
|
||||
'driver': 'bar',
|
||||
'options': {
|
||||
'user': 'jenny',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert interpolate_environment_variables(services, 'service') == expected
|
||||
|
||||
|
||||
def test_interpolate_environment_variables_in_volumes(mock_env):
|
||||
volumes = {
|
||||
'data': {
|
||||
'driver': '$FOO',
|
||||
'driver_opts': {
|
||||
'max': 2,
|
||||
'user': '${USER}'
|
||||
}
|
||||
},
|
||||
'other': None,
|
||||
}
|
||||
expected = {
|
||||
'data': {
|
||||
'driver': 'bar',
|
||||
'driver_opts': {
|
||||
'max': 2,
|
||||
'user': 'jenny'
|
||||
}
|
||||
},
|
||||
'other': {},
|
||||
}
|
||||
assert interpolate_environment_variables(volumes, 'volume') == expected
|
||||
Loading…
Add table
Add a link
Reference in a new issue