mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Add tests for _check_user usage
This commit is contained in:
parent
84e90b20bf
commit
5a4ea6d2d2
3 changed files with 108 additions and 0 deletions
|
@ -206,3 +206,38 @@ def test_copy(tmp_path):
|
|||
)
|
||||
res = filestate.copy_(name, source, group=group, preserve=False)
|
||||
assert res == ret
|
||||
|
||||
|
||||
def test_copy_test_mode_user_group_not_present():
|
||||
"""
|
||||
Test file copy in test mode with no user or group existing
|
||||
"""
|
||||
source = "/tmp/src_copy_no_user_group_test_mode"
|
||||
filename = "/tmp/copy_no_user_group_test_mode"
|
||||
with patch.dict(
|
||||
filestate.__salt__,
|
||||
{
|
||||
"file.group_to_gid": MagicMock(side_effect=["1234", "", ""]),
|
||||
"file.user_to_uid": MagicMock(side_effect=["", "4321", ""]),
|
||||
"file.get_mode": MagicMock(return_value="0644"),
|
||||
},
|
||||
), patch.dict(filestate.__opts__, {"test": True}), patch.object(
|
||||
os.path, "exists", return_value=True
|
||||
):
|
||||
ret = filestate.copy_(
|
||||
source, filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.copy_(
|
||||
source, filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.copy_(
|
||||
source, filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
|
|
@ -598,3 +598,45 @@ def test_mod_run_check_cmd():
|
|||
assert filestate.mod_run_check_cmd(cmd, filename) == ret
|
||||
|
||||
assert filestate.mod_run_check_cmd(cmd, filename)
|
||||
|
||||
|
||||
def test_recurse_test_mode_user_group_not_present():
|
||||
"""
|
||||
Test file recurse in test mode with no user or group existing
|
||||
"""
|
||||
filename = "/tmp/recurse_no_user_group_test_mode"
|
||||
source = "salt://tmp/src_recurse_no_user_group_test_mode"
|
||||
mock_l = MagicMock(return_value=[])
|
||||
mock_emt = MagicMock(return_value=["tmp/src_recurse_no_user_group_test_mode"])
|
||||
with patch.dict(
|
||||
filestate.__salt__,
|
||||
{
|
||||
"file.group_to_gid": MagicMock(side_effect=["1234", "", ""]),
|
||||
"file.user_to_uid": MagicMock(side_effect=["", "4321", ""]),
|
||||
"file.get_mode": MagicMock(return_value="0644"),
|
||||
"file.source_list": MagicMock(return_value=[source, ""]),
|
||||
"cp.list_master_dirs": mock_emt,
|
||||
"cp.list_master": mock_l,
|
||||
},
|
||||
), patch.dict(filestate.__opts__, {"test": True}), patch.object(
|
||||
os.path, "exists", return_value=True
|
||||
), patch.object(
|
||||
os.path, "isdir", return_value=True
|
||||
):
|
||||
ret = filestate.recurse(
|
||||
filename, source, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.recurse(
|
||||
filename, source, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.recurse(
|
||||
filename, source, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
|
|
@ -374,3 +374,34 @@ def test_managed():
|
|||
filestate.managed(name, user=user, group=group)
|
||||
== ret
|
||||
)
|
||||
|
||||
|
||||
def test_managed_test_mode_user_group_not_present():
|
||||
"""
|
||||
Test file managed in test mode with no user or group existing
|
||||
"""
|
||||
filename = "/tmp/managed_no_user_group_test_mode"
|
||||
with patch.dict(
|
||||
filestate.__salt__,
|
||||
{
|
||||
"file.group_to_gid": MagicMock(side_effect=["1234", "", ""]),
|
||||
"file.user_to_uid": MagicMock(side_effect=["", "4321", ""]),
|
||||
},
|
||||
), patch.dict(filestate.__opts__, {"test": True}):
|
||||
ret = filestate.managed(
|
||||
filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.managed(
|
||||
filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
||||
ret = filestate.managed(
|
||||
filename, group="nonexistinggroup", user="nonexistinguser"
|
||||
)
|
||||
assert ret["result"] is not False
|
||||
assert "is not available" not in ret["comment"]
|
||||
|
|
Loading…
Add table
Reference in a new issue