diff options
Diffstat (limited to 'test/units/plugins/become/test_su.py')
-rw-r--r-- | test/units/plugins/become/test_su.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/units/plugins/become/test_su.py b/test/units/plugins/become/test_su.py new file mode 100644 index 0000000..bf74a4c --- /dev/null +++ b/test/units/plugins/become/test_su.py @@ -0,0 +1,30 @@ +# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> +# (c) 2020 Ansible Project +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import re + +from ansible import context +from ansible.plugins.loader import become_loader, shell_loader + + +def test_su(mocker, parser, reset_cli_args): + options = parser.parse_args([]) + context._init_global_context(options) + + su = become_loader.get('su') + sh = shell_loader.get('sh') + sh.executable = "/bin/bash" + + su.set_options(direct={ + 'become_user': 'foo', + 'become_flags': '', + }) + + cmd = su.build_become_command('/bin/foo', sh) + assert re.match(r"""su\s+foo -c '/bin/bash -c '"'"'echo BECOME-SUCCESS-.+?; /bin/foo'"'"''""", cmd) |