Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/become/test_run0.py

raw
1 # Copyright (c) 2024 Ansible Project
2 #
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 import re
9
10 from ansible import context
11
12 from .helper import call_become_plugin
13
14
15 def test_run0_basic(mocker, parser, reset_cli_args):
16 options = parser.parse_args([])
17 context._init_global_context(options)
18
19 default_cmd = "/bin/foo"
20 default_exe = "/bin/sh"
21 run0_exe = "run0"
22
23 success = "BECOME-SUCCESS-.+?"
24
25 task = {
26 "become_method": "community.general.run0",
27 }
28 var_options = {}
29 cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
30 assert (
31 re.match(
32 f"SYSTEMD_COLORS=0 {run0_exe} --user=root {default_exe} -c 'echo {success}; {default_cmd}'",
33 cmd,
34 )
35 is not None
36 )
37
38
39 def test_run0_flags(mocker, parser, reset_cli_args):
40 options = parser.parse_args([])
41 context._init_global_context(options)
42
43 default_cmd = "/bin/foo"
44 default_exe = "/bin/sh"
45 run0_exe = "run0"
46 run0_flags = "--nice=15"
47
48 success = "BECOME-SUCCESS-.+?"
49
50 task = {
51 "become_method": "community.general.run0",
52 "become_flags": run0_flags,
53 }
54 var_options = {}
55 cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
56 assert (
57 re.match(
58 f"SYSTEMD_COLORS=0 {run0_exe} --user=root --nice=15 {default_exe} -c 'echo {success}; {default_cmd}'",
59 cmd,
60 )
61 is not None
62 )