Fix environment resolution

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-03-12 13:59:23 +00:00
commit 528bed9ef6
7 changed files with 77 additions and 33 deletions

View file

@ -0,0 +1,4 @@
web:
image: busybox
command: /bin/true
env_file: ./test.env

1
tests/fixtures/env-file/test.env vendored Normal file
View file

@ -0,0 +1 @@
FOO=1

View file

@ -1,5 +1,6 @@
from __future__ import absolute_import
import sys
import os
from six import StringIO
from mock import patch
@ -23,6 +24,12 @@ class CLITestCase(DockerClientTestCase):
@property
def project(self):
# Hack: allow project to be overridden. This needs refactoring so that
# the project object is built exactly once, by the command object, and
# accessed by the test case object.
if hasattr(self, '_project'):
return self._project
return self.command.get_project(self.command.get_config_path())
def test_help(self):
@ -409,3 +416,12 @@ class CLITestCase(DockerClientTestCase):
self.assertEqual(get_port(3000), container.get_local_port(3000))
self.assertEqual(get_port(3001), "0.0.0.0:9999")
self.assertEqual(get_port(3002), "")
def test_env_file_relative_to_compose_file(self):
config_path = os.path.abspath('tests/fixtures/env-file/docker-compose.yml')
self.command.dispatch(['-f', config_path, 'up', '-d'], None)
self._project = self.command.get_project(config_path)
containers = self.project.containers(stopped=True)
self.assertEqual(len(containers), 1)
self.assertIn("FOO=1", containers[0].get('Config.Env'))

View file

@ -30,7 +30,7 @@ class DockerClientTestCase(unittest.TestCase):
return Service(
project='composetest',
client=self.client,
**make_service_dict(name, kwargs)
**make_service_dict(name, kwargs, working_dir='.')
)
def check_build(self, *args, **kwargs):

View file

@ -90,7 +90,8 @@ class ConfigTest(unittest.TestCase):
def test_env_from_file(self):
service_dict = config.make_service_dict(
'foo',
{'env_file': 'tests/fixtures/env/one.env'},
{'env_file': 'one.env'},
'tests/fixtures/env',
)
self.assertEqual(
service_dict['environment'],
@ -100,12 +101,8 @@ class ConfigTest(unittest.TestCase):
def test_env_from_multiple_files(self):
service_dict = config.make_service_dict(
'foo',
{
'env_file': [
'tests/fixtures/env/one.env',
'tests/fixtures/env/two.env',
],
},
{'env_file': ['one.env', 'two.env']},
'tests/fixtures/env',
)
self.assertEqual(
service_dict['environment'],
@ -113,10 +110,10 @@ class ConfigTest(unittest.TestCase):
)
def test_env_nonexistent_file(self):
options = {'env_file': 'tests/fixtures/env/nonexistent.env'}
options = {'env_file': 'nonexistent.env'}
self.assertRaises(
config.ConfigurationError,
lambda: config.make_service_dict('foo', options),
lambda: config.make_service_dict('foo', options, 'tests/fixtures/env'),
)
@mock.patch.dict(os.environ)
@ -126,7 +123,8 @@ class ConfigTest(unittest.TestCase):
os.environ['ENV_DEF'] = 'E3'
service_dict = config.make_service_dict(
'foo',
{'env_file': 'tests/fixtures/env/resolve.env'},
{'env_file': 'resolve.env'},
'tests/fixtures/env',
)
self.assertEqual(
service_dict['environment'],