write tests

This commit is contained in:
cmcmarrow 2022-02-27 14:00:41 -06:00
parent 4aef948892
commit 266c0e0e92
2 changed files with 19 additions and 5 deletions

View file

@ -394,14 +394,13 @@ def get_jids_filter(count, filter_find_job=True):
def _remove_job_dir(job_path):
"""
Try to remove job dir. If job dir cant be removed then error will be logged.
:param job_path: Path to job
Try to remove job dir. In rare cases NotADirectoryError can raise because node corruption.
:param job_path: Path to job
"""
# Remove remove job dir
# Remove job dir
try:
shutil.rmtree(job_path)
except OSError as err:
except NotADirectoryError as err:
log.error("Unable to remove %s: %s", job_path, err)

View file

@ -0,0 +1,15 @@
from salt.returners.local_cache import _remove_job_dir
from tests.support.mock import patch
def test_remove_job_dir():
# Test that _remove_job_dir job will NotADirectoryError error
with patch("shutil.rmtree", side_effect=NotADirectoryError("Node Corruption!")):
_remove_job_dir("cache.json")
# Test that _remove_job_dir job will not catch other file errors
with patch("shutil.rmtree", side_effect=OSError()):
try:
_remove_job_dir("cache.json")
except OSError:
pass