From bfa640444e09f53cfc0d1042f0e562cab8064b0f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 22 Jun 2021 15:11:32 -0400 Subject: [PATCH] agent: Test filter_files() with multiple filters --- .../infection_monkey/utils/test_dir_utils.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/monkey/tests/unit_tests/infection_monkey/utils/test_dir_utils.py b/monkey/tests/unit_tests/infection_monkey/utils/test_dir_utils.py index 1b193fc3e..b8ff47a65 100644 --- a/monkey/tests/unit_tests/infection_monkey/utils/test_dir_utils.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/test_dir_utils.py @@ -4,7 +4,7 @@ from infection_monkey.utils.dir_utils import ( get_all_regular_files_in_directory, ) -FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz"] +FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz", "2.png", "2.mpg"] SUBDIRS = ["subdir1", "subdir2"] @@ -70,6 +70,18 @@ def test_filter_files__all_true(tmp_path): assert sorted(filtered_files) == expected_return_value +def test_filter_files__multiple_filters(tmp_path): + files = add_files_to_dir(tmp_path) + expected_return_value = sorted(files[4:6]) + + files_in_dir = get_all_regular_files_in_directory(tmp_path) + filtered_files = filter_files( + files_in_dir, [lambda f: f.name.startswith("2"), lambda f: f.name.endswith("g")] + ) + + assert sorted(filtered_files) == expected_return_value + + def test_file_extension_filter(tmp_path): valid_extensions = {".zip", ".xyz"}