def test_interpolate_environment_variables_in_services(mock_env): services = { 'servivea': { 'image': 'example:${USER}', 'entrypoint': '/bin/bash', 'volumes': ['$FOO:/target'], 'read_only': '${RO}', 'cpu_shares': '${CPU_SHARES}', 'logging': { 'driver': '${FOO}', 'options': { 'user': '******', } } } } expected = { 'servivea': { 'image': 'example:jenny', 'entrypoint': '/bin/bash', 'volumes': ['bar:/target'], 'read_only': False, 'cpu_shares': 512, 'logging': { 'driver': 'bar', 'options': { 'user': '******', } } } } assert interpolate_environment_variables(services, 'service', load_jsonschema('service', V2_0)) == expected
def test_interpolate_environment_variables_array_numbers_in_services(mock_env): services = { 'servivea': { 'expose': '${PORTS}', 'ports': [8080, '${SINGLE_PORT}'] } } expected = { 'servivea': { 'expose': [8080, 8089], 'ports': [8080, 8787] } } assert interpolate_environment_variables(services, 'service', load_jsonschema('service', V2_0)) == expected
def test_interpolate_environment_variables_array_element_in_services(mock_env): services = { 'servivea': { 'image': 'example:${USER}', 'volumes': ['/tmp/bar:/bar', '${VOLUMES_ITEM}'], 'cpu_shares': '${CPU_SHARES}', } } expected = { 'servivea': { 'image': 'example:jenny', 'volumes': ['/tmp/bar:/bar', '/tmp/foo:/foo'], 'cpu_shares': 512, } } assert interpolate_environment_variables(services, 'service', load_jsonschema('service', V2_0)) == expected
def test_interpolate_environment_variables_in_volumes(mock_env): volumes = { 'data': { 'driver': '$FOO', 'driver_opts': { 'max': 2, 'user': '******' } }, 'other': None, } expected = { 'data': { 'driver': 'bar', 'driver_opts': { 'max': 2, 'user': '******' } }, 'other': {}, } assert interpolate_environment_variables(volumes, 'volume', load_jsonschema('service', V2_0)) == expected