diff --git a/tests/pytests/functional/modules/test_win_file.py b/tests/pytests/functional/modules/test_win_file.py index a4423bcfdeab..730b8dbd85a9 100644 --- a/tests/pytests/functional/modules/test_win_file.py +++ b/tests/pytests/functional/modules/test_win_file.py @@ -8,20 +8,44 @@ from salt.modules import win_file pytestmark = [ + pytest.mark.windows_whitelisted, pytest.mark.skip_unless_on_windows, ] +@pytest.fixture +def configure_loader_modules(minion_opts, modules): + utils = salt.loader.utils(minion_opts) + return { + win_file: { + "__opts__": minion_opts, + "__salt__": modules, + "__utils__": utils, + }, + } + @pytest.fixture def user(): return salt.utils.user.get_user() -def test_is_link(tmp_path): +@pytest.mark.flaky_jail +def test_symlink(tmp_path): # TODO only test when priv are given tmp_path = str(tmp_path) - assert ( - win_file.is_link(tmp_path) is True - ) # THIS should be false TODO make bug report + file = os.path.join(tmp_path, "t.txt") + with salt.utils.files.fopen(file, "w"): + pass + assert os.path.isfile(file) is True + link = os.path.join(tmp_path, "l") + assert win_file.is_link(link) is False + win_file.symlink(file, link, force=True) + assert os.path.isfile(file) is True + assert win_file.is_link(link) is True + + +def test_is_link_false(tmp_path): + tmp_path = str(tmp_path) + assert win_file.is_link(tmp_path) is False assert win_file.is_link(os.path.join(tmp_path, "made_up_path")) is False @@ -37,9 +61,7 @@ def test_user(tmp_path, user): path = os.path.join(tmp_path, "dir") assert win_file.mkdir(path, owner=user) is True assert os.path.isdir(path) - assert win_file.get_user(path) == user - assert win_file.get_group(path) == user - assert isinstance(win_file.get_gid(path), int) is True + assert win_file.get_user(path) in user def test_fake_user(tmp_path, user): @@ -50,10 +72,73 @@ def test_fake_user(tmp_path, user): win_file.mkdir(path, owner=user) -def test_version(tmp_path): +def test_version(): + assert len(win_file.version("C:\\Windows\\System32\\wow64.dll").split(".")) == 4 + +def test_version_empty(tmp_path): tmp_path = str(tmp_path) file = os.path.join(tmp_path, "t.txt") - with salt.utils.files.fopen(file): + with salt.utils.files.fopen(file, "w"): pass assert os.path.isfile(file) is True assert win_file.version(file) == "" + + +def test_version_details(): + details = win_file.version_details("C:\\Windows\\System32\\wow64.dll") + assert isinstance(details, dict) is True + assert details["Comments"] is None + assert details["CompanyName"] == "Microsoft Corporation" + assert isinstance(details["FileDescription"], str) is True + + +def test_get_attributes(tmp_path): + tmp_path = str(tmp_path) + file = os.path.join(tmp_path, "t.txt") + with salt.utils.files.fopen(file, "w"): + pass + assert os.path.isfile(file) is True + attributes = win_file.get_attributes(file) + assert isinstance(attributes, dict) is True + assert attributes["archive"] == True + assert attributes["reparsePoint"] == False + assert attributes["compressed"] == False + assert attributes["directory"] == False + assert attributes["encrypted"] == False + assert attributes["hidden"] == False + assert attributes["normal"] == False + assert attributes["notIndexed"] == False + assert attributes["offline"] == False + assert attributes["readonly"] == False + assert attributes["system"] == False + assert attributes["temporary"] == False + assert attributes["mountedVolume"] == False + assert attributes["symbolicLink"] == False + + +def test_set_attributes(tmp_path): + win_file.set_attributes( + path, + archive=None, + hidden=None, + normal=None, + notIndexed=None, + readonly=None, + system=None, + temporary=None) + +def test_remove(tmp_path): + tmp_path = str(tmp_path) + file = os.path.join(tmp_path, "t.txt") + with salt.utils.files.fopen(file, "w"): + pass + assert os.path.isfile(file) is True + assert win_file.remove(file) is True + +def test_remove_force(tmp_path): + tmp_path = str(tmp_path) + file = os.path.join(tmp_path, "t.txt") + with salt.utils.files.fopen(file, "w"): + pass + assert os.path.isfile(file) is True + assert win_file.remove(file, force=True) is True