diff --git a/tests/pytests/unit/states/file/test_copy.py b/tests/pytests/unit/states/file/test_copy.py index 579c7cf0c80..d7becf580c8 100644 --- a/tests/pytests/unit/states/file/test_copy.py +++ b/tests/pytests/unit/states/file/test_copy.py @@ -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"] diff --git a/tests/pytests/unit/states/file/test_filestate.py b/tests/pytests/unit/states/file/test_filestate.py index 6fb50a817bf..f7daf51b5a6 100644 --- a/tests/pytests/unit/states/file/test_filestate.py +++ b/tests/pytests/unit/states/file/test_filestate.py @@ -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"] diff --git a/tests/pytests/unit/states/file/test_managed.py b/tests/pytests/unit/states/file/test_managed.py index 128c808e97f..0f5da2dac27 100644 --- a/tests/pytests/unit/states/file/test_managed.py +++ b/tests/pytests/unit/states/file/test_managed.py @@ -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"]