Skip to content

Commit

Permalink
Add Pedro's suggested changes
Browse files Browse the repository at this point in the history
The tests are still failing... I'll try a rebase
  • Loading branch information
twangboy committed Jun 27, 2024
1 parent 3b839c7 commit 36ac801
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions tests/pytests/unit/fileclient/test_fileclient_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

log = logging.getLogger(__name__)


SUBDIR = "subdir"


def _saltenvs():
return ("base", "dev")


@pytest.fixture(params=_saltenvs())
def saltenv(request):
return request.param


def _subdir_files():
return ("foo.txt", "bar.txt", "baz.txt")

Expand Down Expand Up @@ -102,7 +106,7 @@ def _new_dir(path):


@pytest.mark.parametrize("subdir", [SUBDIR, f"{SUBDIR}{os.sep}"])
def test_cache_dir(mocked_opts, minion_opts, subdir):
def test_cache_dir(mocked_opts, minion_opts, subdir, saltenv):
"""
Ensure entire directory is cached to correct location
"""
Expand All @@ -111,31 +115,30 @@ def test_cache_dir(mocked_opts, minion_opts, subdir):

with patch.dict(fileclient.__opts__, patched_opts):
client = fileclient.get_file_client(fileclient.__opts__, pillar=False)
for saltenv in _saltenvs():
assert client.cache_dir(
"salt://{}".format(subdir),
assert client.cache_dir(
f"salt://{subdir}",
saltenv,
exclude_pat="*foo.txt",
cachedir=None,
)
for subdir_file in _subdir_files():
cache_loc = os.path.join(
fileclient.__opts__["cachedir"],
"files",
saltenv,
exclude_pat="*foo.txt",
cachedir=None,
subdir,
subdir_file,
)
for subdir_file in _subdir_files():
cache_loc = os.path.join(
fileclient.__opts__["cachedir"],
"files",
saltenv,
subdir,
subdir_file,
)
if not subdir_file.endswith("foo.txt"):
with salt.utils.files.fopen(cache_loc) as fp_:
content = fp_.read()
log.debug("cache_loc = %s", cache_loc)
log.debug("content = %s", content)
assert subdir_file in content
assert SUBDIR in content
assert saltenv in content
else:
assert not os.path.exists(cache_loc)
if not subdir_file.endswith("foo.txt"):
with salt.utils.files.fopen(cache_loc) as fp_:
content = fp_.read()
log.debug("cache_loc = %s", cache_loc)
log.debug("content = %s", content)
assert subdir_file in content
assert SUBDIR in content
assert saltenv in content
else:
assert not os.path.exists(cache_loc)


def test_cache_dir_include_empty(mocked_opts, minion_opts, fs_root):
Expand All @@ -162,7 +165,7 @@ def test_cache_dir_include_empty(mocked_opts, minion_opts, fs_root):
)
os.makedirs(os.path.join(fs_root, saltenv, "emptydir"))
assert client.cache_dir(
"salt://{}".format(SUBDIR), saltenv, cachedir=None, include_empty=True
f"salt://{SUBDIR}", saltenv, cachedir=None, include_empty=True
)
for subdir_file in _subdir_files():
cache_loc = os.path.join(
Expand Down

0 comments on commit 36ac801

Please sign in to comment.