Skip to content

Commit

Permalink
Modify tests to use user temp directory
Browse files Browse the repository at this point in the history
Modifies the win_dacl tests to use the user temp directory as using
any other directories breaks the expected matching perms
  • Loading branch information
barneysowood committed Jan 22, 2025
1 parent e8e5eb6 commit 13538c4
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions tests/pytests/functional/utils/win_dacl/test_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import tempfile

import pytest

import salt.utils.win_dacl as win_dacl
Expand All @@ -18,9 +21,24 @@ def configure_loader_modules(minion_opts):
}


@pytest.fixture(scope="module")
def user_temp_dir():
"""
Return the user's temp directory if available
Some of the tests fail if using system temp directories
"""
if "TMP" in os.environ and os.path.exists(os.environ["TMP"]):
return os.environ["TMP"]
return tempfile.gettempdir()


@pytest.fixture(scope="function")
def test_file():
with pytest.helpers.temp_file("dacl_test.file") as test_file:
def test_file(tmp_path_factory, user_temp_dir):

with pytest.helpers.temp_file(
"dacl_test.file", directory=user_temp_dir
) as test_file:
yield test_file


Expand Down Expand Up @@ -671,8 +689,10 @@ def test_get_set_inheritance(test_file):
assert result is False


def test_copy_security():
with pytest.helpers.temp_file("source_test.file") as source:
def test_copy_security(user_temp_dir):
with pytest.helpers.temp_file(
"source_test.file", directory=user_temp_dir
) as source:
# Set permissions on Source
result = win_dacl.set_permissions(
obj_name=str(source),
Expand All @@ -697,7 +717,9 @@ def test_copy_security():
)
assert result is True

with pytest.helpers.temp_file("target_test.file") as target:
with pytest.helpers.temp_file(
"target_test.file", directory=user_temp_dir
) as target:
# Copy security from Source to Target
result = win_dacl.copy_security(source=str(source), target=str(target))
assert result is True
Expand Down

0 comments on commit 13538c4

Please sign in to comment.