mirror of https://github.com/docker/compose.git
Test get_project_name from env file
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
d55fc85fea
commit
f48da96e8b
|
@ -49,7 +49,7 @@ class Environment(dict):
|
|||
return result
|
||||
env_file_path = os.path.join(base_dir, '.env')
|
||||
try:
|
||||
result.update(env_vars_from_file(env_file_path))
|
||||
return cls(env_vars_from_file(env_file_path))
|
||||
except ConfigurationError:
|
||||
pass
|
||||
return result
|
||||
|
|
|
@ -3,6 +3,8 @@ from __future__ import absolute_import
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import docker
|
||||
import py
|
||||
|
@ -57,6 +59,22 @@ class CLITestCase(unittest.TestCase):
|
|||
project_name = get_project_name(base_dir)
|
||||
self.assertEquals('simplecomposefile', project_name)
|
||||
|
||||
@mock.patch.dict(os.environ)
|
||||
def test_project_name_with_environment_file(self):
|
||||
base_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
name = 'namefromenvfile'
|
||||
with open(os.path.join(base_dir, '.env'), 'w') as f:
|
||||
f.write('COMPOSE_PROJECT_NAME={}'.format(name))
|
||||
project_name = get_project_name(base_dir)
|
||||
assert project_name == name
|
||||
|
||||
# Environment has priority over .env file
|
||||
os.environ['COMPOSE_PROJECT_NAME'] = 'namefromenv'
|
||||
assert get_project_name(base_dir) == os.environ['COMPOSE_PROJECT_NAME']
|
||||
finally:
|
||||
shutil.rmtree(base_dir)
|
||||
|
||||
def test_get_project(self):
|
||||
base_dir = 'tests/fixtures/longer-filename-composefile'
|
||||
project = get_project(base_dir)
|
||||
|
|
Loading…
Reference in New Issue