agent: Test filter_files() with multiple filters

This commit is contained in:
Mike Salvatore 2021-06-22 15:11:32 -04:00
parent 30f88ca319
commit bfa640444e
1 changed files with 13 additions and 1 deletions

View File

@ -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"}