dumb-init/tests/cwd_test.py

29 lines
846 B
Python
Raw Permalink Normal View History

2020-12-03 13:02:40 +03:00
import os
import shutil
2021-10-07 21:21:16 +03:00
from subprocess import PIPE
from subprocess import run
2020-12-03 13:02:40 +03:00
import pytest
2021-10-07 21:21:16 +03:00
2020-12-03 13:02:40 +03:00
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
def test_working_directories():
"""The child process must start in the working directory in which
dumb-init was invoked, but dumb-init itself should not keep a
reference to that."""
# We need absolute path to dumb-init since we pass cwd=/tmp to get
# predictable output - so we can't rely on dumb-init being found
# in the "." directory.
dumb_init = os.path.realpath(shutil.which('dumb-init'))
2021-10-07 21:21:16 +03:00
proc = run(
(
dumb_init,
'sh', '-c', 'readlink /proc/$PPID/cwd && readlink /proc/$$/cwd',
),
cwd='/tmp', stdout=PIPE, stderr=PIPE,
)
2020-12-03 13:02:40 +03:00
assert proc.returncode == 0
assert proc.stdout == b'/\n/tmp\n'