Add integration tests regarding environment

This covers what was included in #6800

Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
This commit is contained in:
Ulysses Souza 2019-07-31 01:58:16 +02:00
parent 7a7c9ff67a
commit b03889ac2a
5 changed files with 34 additions and 3 deletions

View File

@ -64,6 +64,12 @@ def wait_on_process(proc, returncode=0):
return ProcessResult(stdout.decode('utf-8'), stderr.decode('utf-8'))
def dispatch(base_dir, options, project_options=None, returncode=0):
project_options = project_options or []
proc = start_process(base_dir, project_options + options)
return wait_on_process(proc, returncode=returncode)
def wait_on_condition(condition, delay=0.1, timeout=40):
start_time = time.time()
while not condition():
@ -151,9 +157,7 @@ class CLITestCase(DockerClientTestCase):
return self._project
def dispatch(self, options, project_options=None, returncode=0):
project_options = project_options or []
proc = start_process(self.base_dir, project_options + options)
return wait_on_process(proc, returncode=returncode)
return dispatch(self.base_dir, options, project_options, returncode)
def execute(self, container, cmd):
# Remove once Hijack and CloseNotifier sign a peace treaty

View File

@ -0,0 +1,2 @@
WHEREAMI
DEFAULT_CONF_LOADED=true

View File

@ -0,0 +1 @@
WHEREAMI=override

View File

@ -0,0 +1,6 @@
version: '3.7'
services:
test:
image: busybox
env_file: .env.conf
entrypoint: env

View File

@ -7,7 +7,10 @@ from ddt import data
from ddt import ddt
from .. import mock
from ..acceptance.cli_test import dispatch
from compose.cli.command import get_project
from compose.cli.command import project_from_options
from compose.config.environment import Environment
from tests.integration.testcases import DockerClientTestCase
@ -50,3 +53,18 @@ services:
# So no need to have a proper options map, the `COMMAND` key is enough
project_from_options('.', options)
assert fake_log.warn.call_count == 0
class EnvironmentOverrideFileTest(DockerClientTestCase):
def test_env_file_override(self):
base_dir = 'tests/fixtures/env-file-override'
dispatch(base_dir, ['--env-file', '.env.override', 'up'])
project = get_project(project_dir=base_dir,
config_path=['docker-compose.yml'],
environment=Environment.from_env_file(base_dir, '.env.override'),
override_dir=base_dir)
containers = project.containers(stopped=True)
assert len(containers) == 1
assert "WHEREAMI=override" in containers[0].get('Config.Env')
assert "DEFAULT_CONF_LOADED=true" in containers[0].get('Config.Env')
dispatch(base_dir, ['--env-file', '.env.override', 'down'], None)