From 8a216386f4a485c10edf66b25b362a84de86c3d7 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Wed, 5 Aug 2020 13:17:53 +0100 Subject: [PATCH] tests: Test --pass-env, --unset-env Signed-off-by: Simon McVittie <smcv@collabora.com> --- tests/launcher.py | 82 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/tests/launcher.py b/tests/launcher.py index c6f96825c..be470e257 100755 --- a/tests/launcher.py +++ b/tests/launcher.py @@ -5,6 +5,7 @@ import logging import os +import shutil import signal import subprocess import sys @@ -56,6 +57,9 @@ class TestLauncher(BaseTest): def test_socket_directory(self) -> None: with tempfile.TemporaryDirectory(prefix='test-') as temp: + printf_symlink = os.path.join(temp, 'printf=symlink') + os.symlink(shutil.which('printf'), printf_symlink) + proc = subprocess.Popen( [ 'env', @@ -132,7 +136,8 @@ class TestLauncher(BaseTest): completed = run_subprocess( [ - 'env', 'PV_TEST_VAR=not-inherited', + 'env', + 'PV_TEST_VAR=not-inherited', ] + self.launch + [ '--socket', socket, '--', @@ -144,6 +149,74 @@ class TestLauncher(BaseTest): ) self.assertEqual(completed.stdout, b'from-launcher') + completed = run_subprocess( + [ + 'env', + '-u', 'PV_TEST_VAR', + 'PV_TEST_VAR_ONE=one', + 'PV_TEST_VAR_TWO=two', + ] + self.launch + [ + '--pass-env=PV_TEST_VAR', + '--pass-env-matching=PV_TEST_VAR_*', + '--socket', socket, + '--', + 'sh', '-euc', + 'printf \'%s\' ' + '"' + '${PV_TEST_VAR-cleared}' + '${PV_TEST_VAR_ONE}' + '${PV_TEST_VAR_TWO}' + '"', + ], + check=True, + stdout=subprocess.PIPE, + stderr=2, + ) + self.assertEqual(completed.stdout, b'clearedonetwo') + + completed = run_subprocess( + [ + 'env', '-u', 'PV_TEST_VAR', + ] + self.launch + [ + '--env=PV_TEST_VAR=nope', + '--pass-env=PV_TEST_VAR', + '--socket', socket, + '--', + 'sh', '-euc', 'printf \'%s\' "${PV_TEST_VAR-cleared}"', + ], + check=True, + stdout=subprocess.PIPE, + stderr=2, + ) + self.assertEqual(completed.stdout, b'cleared') + + completed = run_subprocess( + self.launch + [ + '--env=PV_TEST_VAR=nope', + '--unset-env=PV_TEST_VAR', + '--socket', socket, + '--', + 'sh', '-euc', 'printf \'%s\' "${PV_TEST_VAR-cleared}"', + ], + check=True, + stdout=subprocess.PIPE, + stderr=2, + ) + self.assertEqual(completed.stdout, b'cleared') + + completed = run_subprocess( + self.launch + [ + '--unset-env=PV_TEST_VAR', + '--socket', socket, + '--', + printf_symlink, 'hello', + ], + check=True, + stdout=subprocess.PIPE, + stderr=2, + ) + self.assertEqual(completed.stdout, b'hello') + completed = run_subprocess( self.launch + [ '--clear-env', @@ -158,7 +231,12 @@ class TestLauncher(BaseTest): self.assertEqual(completed.stdout, b'cleared') completed = run_subprocess( - self.launch + [ + [ + 'env', + 'PV_TEST_VAR=not-inherited', + ] + self.launch + [ + '--pass-env=PV_TEST_VAR', + '--env=PV_TEST_VAR=nope', '--env=PV_TEST_VAR=overridden', '--socket', socket, '--', -- GitLab