From fe2b69254797309c28ef95f15991e971dc3d7511 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 20 Nov 2019 13:32:07 +0100 Subject: [PATCH] testcase for compose file read from stdin Signed-off-by: Nicolas De Loof --- tests/acceptance/cli_test.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index a03d56567..b1790fdcf 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -48,6 +48,7 @@ BUILD_PULL_TEXT = 'Status: Image is up to date for busybox:1.27.2' def start_process(base_dir, options): proc = subprocess.Popen( ['docker-compose'] + options, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=base_dir) @@ -55,8 +56,8 @@ def start_process(base_dir, options): return proc -def wait_on_process(proc, returncode=0): - stdout, stderr = proc.communicate() +def wait_on_process(proc, returncode=0, stdin=None): + stdout, stderr = proc.communicate(input=stdin) if proc.returncode != returncode: print("Stderr: {}".format(stderr)) print("Stdout: {}".format(stdout)) @@ -64,10 +65,10 @@ 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): +def dispatch(base_dir, options, project_options=None, returncode=0, stdin=None): project_options = project_options or [] proc = start_process(base_dir, project_options + options) - return wait_on_process(proc, returncode=returncode) + return wait_on_process(proc, returncode=returncode, stdin=stdin) def wait_on_condition(condition, delay=0.1, timeout=40): @@ -156,8 +157,8 @@ class CLITestCase(DockerClientTestCase): self._project = get_project(self.base_dir, override_dir=self.override_dir) return self._project - def dispatch(self, options, project_options=None, returncode=0): - return dispatch(self.base_dir, options, project_options, returncode) + def dispatch(self, options, project_options=None, returncode=0, stdin=None): + return dispatch(self.base_dir, options, project_options, returncode, stdin) def execute(self, container, cmd): # Remove once Hijack and CloseNotifier sign a peace treaty @@ -241,6 +242,17 @@ class CLITestCase(DockerClientTestCase): self.base_dir = 'tests/fixtures/v2-full' assert self.dispatch(['config', '--quiet']).stdout == '' + def test_config_stdin(self): + config = b"""version: "3.7" +services: + web: + image: nginx + other: + image: alpine +""" + result = self.dispatch(['-f', '-', 'config', '--services'], stdin=config) + assert set(result.stdout.rstrip().split('\n')) == {'web', 'other'} + def test_config_with_hash_option(self): self.base_dir = 'tests/fixtures/v2-full' result = self.dispatch(['config', '--hash=*'])