Skip to content

Commit

Permalink
parser tests => sort in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouaix committed Nov 19, 2024
1 parent 7c3ece8 commit d2acbb3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,19 @@ pub fn build_log(

/// Parse all UUID files in provided directory. The directory should follow the same layout as the live system (ex: path/to/files/<two character UUID>/<remaining UUID name>)
pub fn collect_strings(path: &str) -> Result<Vec<UUIDText>, ParserError> {
let paths_results = fs::read_dir(path);

let paths = paths_results.map_err(|err| {
let paths = fs::read_dir(path).map_err(|err| {
error!("[macos-unifiedlogs] Failed to read directory path: {err:?}");
ParserError::Dir
})?;

let mut entries = paths
let entries = paths
.flat_map(|path| {
path.inspect_err(|err| {
error!("[macos-unifiedlogs] Failed to get directory entry: {err:?}",)
})
.ok()
})
.collect::<Vec<_>>();
entries.sort_by(|a, b| a.file_name().as_os_str().cmp(b.file_name().as_os_str()));

let mut uuidtext_vec: Vec<UUIDText> = Vec::with_capacity(entries.len());
// Start process to read a directory containing subdirectories that contain the uuidtext files
Expand Down Expand Up @@ -440,21 +437,24 @@ mod tests {
let mut test_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_path.push("tests/test_data/system_logs_big_sur.logarchive");

let strings_results = collect_strings(&test_path.display().to_string()).unwrap();
let mut strings_results = collect_strings(&test_path.display().to_string()).unwrap();
assert_eq!(strings_results.len(), 536);

strings_results.sort_by(|a, b| a.uuid.cmp(&b.uuid));

assert_eq!(strings_results[0].signature, 1719109785);
assert_eq!(strings_results[0].uuid, "B6B65F4DC53ED38FEB0DDF61809853");
assert_eq!(strings_results[0].entry_descriptors.len(), 2);
assert_eq!(strings_results[0].footer_data.len(), 1707);
assert_eq!(strings_results[0].number_entries, 2);
assert_eq!(strings_results[0].uuid, "004EAF1C2B310DA0383BE3D60B80E8");
assert_eq!(strings_results[0].entry_descriptors.len(), 1);
assert_eq!(strings_results[0].footer_data.len(), 2847);
assert_eq!(strings_results[0].number_entries, 1);
assert_eq!(strings_results[0].unknown_minor_version, 1);
assert_eq!(strings_results[0].unknown_major_version, 2);

assert_eq!(strings_results[1].uuid, "D9B97EA2CD39C7A9AF1888E041B9E1");
assert_eq!(strings_results[1].footer_data.len(), 238974);
assert_eq!(strings_results[1].uuid, "00B3D870FB3AE8BDC1BA3A60D0B9A0");
assert_eq!(strings_results[1].footer_data.len(), 2164);

assert_eq!(strings_results[2].uuid, "2578ECF07936A6A882574764C7C785");
assert_eq!(strings_results[2].footer_data.len(), 68714);
assert_eq!(strings_results[2].uuid, "014C44534A3A748476ABD88D376918");
assert_eq!(strings_results[2].footer_data.len(), 19011);
}

#[test]
Expand Down

0 comments on commit d2acbb3

Please sign in to comment.