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 Feb 14, 2024
1 parent ef4e0d2 commit 5321333
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions tests/pytests/unit/fileclient/test_fileclient_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ 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 +107,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 +116,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(
"salt://{}".format(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 Down

0 comments on commit 5321333

Please sign in to comment.