mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
write tests
This commit is contained in:
parent
4aef948892
commit
266c0e0e92
2 changed files with 19 additions and 5 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
15
tests/pytests/unit/returners/test_local_cache.py
Normal file
15
tests/pytests/unit/returners/test_local_cache.py
Normal 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
|
Loading…
Add table
Reference in a new issue