diff --git a/tests/pytests/unit/fileclient/test_fileclient_cache.py b/tests/pytests/unit/fileclient/test_fileclient_cache.py index 64826d041448..4b5851aeab79 100644 --- a/tests/pytests/unit/fileclient/test_fileclient_cache.py +++ b/tests/pytests/unit/fileclient/test_fileclient_cache.py @@ -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") @@ -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 """ @@ -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):