in proxy_agent_shared/src/misc_helpers.rs [439:489]
fn search_files_test() {
let mut temp_test_path = env::temp_dir();
temp_test_path.push("search_files_test");
// clean up and ignore the clean up errors
_ = fs::remove_dir_all(&temp_test_path);
super::try_create_folder(&temp_test_path).unwrap();
let test = TestStruct {
thread_id: super::get_thread_identity(),
date_time_string_with_milliseconds: super::get_date_time_string_with_milliseconds(),
date_time_string: super::get_date_time_string(),
date_time_rfc1123_string: super::get_date_time_rfc1123_string(),
date_time_unix_nano: super::get_date_time_unix_nano(),
long_os_version: super::get_long_os_version(),
current_exe_dir: super::get_current_exe_dir().to_str().unwrap().to_string(),
};
// write 2 json files to the temp_test_path
let json_file = temp_test_path.as_path();
let json_file = json_file.join("test.json");
super::json_write_to_file(&test, &json_file).unwrap();
let json_file = temp_test_path.as_path();
let json_file = json_file.join("test_1.json");
super::json_write_to_file(&test, &json_file).unwrap();
let files = super::search_files(&temp_test_path, "test.json").unwrap();
assert_eq!(
1,
files.len(),
"file count mismatch with 'test.json' search"
);
let files = super::search_files(&temp_test_path, r"^test.*\.json$").unwrap();
assert_eq!(
2,
files.len(),
"file count mismatch with 'test*.json' search"
);
assert_eq!(
"test.json",
super::get_file_name(&files[0]),
"First file name mismatch"
);
assert_eq!(
"test_1.json",
super::get_file_name(&files[1]),
"Second file name mismatch"
);
_ = fs::remove_dir_all(&temp_test_path);
}