Tests: ability to run unitd with specified "--user" option.
@@ -48,6 +48,11 @@ def pytest_addoption(parser):
action="store_true",
help="Run unsafe tests",
)
+ parser.addoption(
+ "--user",
+ type=str,
+ help="Default user for non-privileged processes of unitd",
+ )
unit_instance = {}
@@ -60,6 +65,7 @@ def pytest_configure(config):
option.print_log = config.option.print_log
option.save_log = config.option.save_log
option.unsafe = config.option.unsafe
+ option.user = config.option.user
option.generated_tests = {}
option.current_dir = os.path.abspath(
@@ -283,9 +289,7 @@ def unit_run():
os.mkdir(temp_dir + '/state')
- with open(temp_dir + '/unit.log', 'w') as log:
- unit_instance['process'] = subprocess.Popen(
- [
+ unitd_args = [
unitd,
'--no-daemon',
'--modules',
@@ -300,9 +304,13 @@ def unit_run():
'unix:' + temp_dir + '/control.unit.sock',
'--tmp',
temp_dir,
- ],
- stderr=log,
- )
+ ]
+
+ if option.user:
+ unitd_args.extend(['--user', option.user])
+
+ with open(temp_dir + '/unit.log', 'w') as log:
+ unit_instance['process'] = subprocess.Popen(unitd_args, stderr=log)
if not waitforfiles(temp_dir + '/control.unit.sock'):
_print_log()
