Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Megan Wilhite authored and s0undt3ch committed Sep 14, 2022
1 parent f42caab commit 8b385b9
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions tests/pytests/unit/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile

import pytest
import salt.grains.extra
import salt.modules.cmdmod as cmdmod
import salt.utils.files
import salt.utils.platform
Expand Down Expand Up @@ -936,9 +937,7 @@ def test_runas_env_sudo_group():
when group is passed and use_sudo=True
"""
bundled = [False, True]

for _bundled in bundled:

with patch("pwd.getpwnam") as getpwnam_mock:
with patch("subprocess.Popen") as popen_mock:
popen_mock.return_value = Mock(
Expand Down Expand Up @@ -971,6 +970,9 @@ def test_runas_env_sudo_group():
shell = "/bin/bash"
_user = "foobar"
_group = "foobar"
same_shell = False
if salt.grains.extra.shell()["shell"] == shell:
same_shell = True

cmdmod._run(
"ls",
Expand All @@ -980,9 +982,7 @@ def test_runas_env_sudo_group():
group=_group,
)
if not _bundled:
assert popen_mock.call_args_list[0][0][
0
] == [
exp_ret = [
"sudo",
"-u",
_user,
Expand All @@ -994,10 +994,23 @@ def test_runas_env_sudo_group():
"-c",
sys.executable,
]
if same_shell:
exp_ret = [
"sudo",
"-u",
_user,
"-g",
_group,
"-i",
"--",
sys.executable,
]
assert (
popen_mock.call_args_list[0][0][0]
== exp_ret
)
else:
assert popen_mock.call_args_list[0][0][
0
] == [
exp_ret = [
"sudo",
"-u",
_user,
Expand All @@ -1011,3 +1024,20 @@ def test_runas_env_sudo_group():
sys.executable, file_name
),
]
if same_shell:
exp_ret = [
"sudo",
"-u",
_user,
"-g",
_group,
"-i",
"--",
"{} python {}".format(
sys.executable, file_name
),
]
assert (
popen_mock.call_args_list[0][0][0]
== exp_ret
)

0 comments on commit 8b385b9

Please sign in to comment.