From 885a90728720add3aecaedb92b0b94b369c38dc7 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 28 Sep 2022 16:21:09 +0530 Subject: [PATCH] UT: Add tests for delete_files_by_pattern() in LocalStorageFileRepository --- .../repository/test_local_storage_file_repository.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py index 64541bcbe..c03d615f9 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_local_storage_file_repository.py @@ -143,3 +143,14 @@ def test_open_locked_file(tmp_path, monkeypatch): with patch("builtins.open", Mock(side_effect=Exception())): with pytest.raises(repository.RetrievalError): fss.open_file("locked_file.txt") + + +def test_delete_files_by_pattern(tmp_path): + for filename in ["xyz-1.txt", "abc-2.txt", "pqr-3.txt", "abc-4.txt"]: + (tmp_path / filename).touch() + + fss = LocalStorageFileRepository(tmp_path) + fss.delete_files_by_pattern("abc-*") + + files = list(tmp_path.iterdir()) + assert len(files) == 2