fix: update tests to handle Skipped paths

feat/type-attributes
Tomáš Mládek 2022-10-18 21:00:10 +02:00
parent 6fa4ff0168
commit 9061d32c89
1 changed files with 22 additions and 10 deletions

View File

@ -310,7 +310,7 @@ impl FsStore {
panic!("File {} too large?!", path.display()); panic!("File {} too large?!", path.display());
} }
if size == 0 { if size == 0 {
return Ok(UpdatePathOutcome::Skipped(path.clone())); return Ok(UpdatePathOutcome::Skipped(path));
} }
let mtime = metadata let mtime = metadata
.modified() .modified()
@ -828,8 +828,8 @@ mod test {
let mut tmp_file = File::create(file_path).unwrap(); let mut tmp_file = File::create(file_path).unwrap();
writeln!(tmp_file, "Hello, World!").unwrap(); writeln!(tmp_file, "Hello, World!").unwrap();
let file_path = temp_dir.path().join("empty"); let empty_path = temp_dir.path().join("empty");
File::create(file_path).unwrap(); File::create(&empty_path).unwrap();
// Initialize database // Initialize database
let open_result = UpEndDatabase::open(&temp_dir, true).unwrap(); let open_result = UpEndDatabase::open(&temp_dir, true).unwrap();
@ -843,9 +843,11 @@ mod test {
assert!(rescan_result.is_ok()); assert!(rescan_result.is_ok());
let rescan_result = rescan_result.unwrap(); let rescan_result = rescan_result.unwrap();
assert_eq!(rescan_result.len(), 3); assert_eq!(rescan_result.len(), 3);
rescan_result rescan_result.into_iter().for_each(|outcome| match outcome {
.into_iter() UpdatePathOutcome::Added(_) => assert!(true),
.for_each(|outcome| assert!(matches!(outcome, UpdatePathOutcome::Added(_)))); UpdatePathOutcome::Skipped(path) => assert_eq!(path, empty_path),
outcome => panic!("Unexpected outcome: {:?}", outcome),
});
// Modification-less rescan // Modification-less rescan
let job = job_container.add_job("RESCAN", "TEST JOB").unwrap(); let job = job_container.add_job("RESCAN", "TEST JOB").unwrap();
@ -854,9 +856,12 @@ mod test {
assert!(rescan_result.is_ok()); assert!(rescan_result.is_ok());
let rescan_result = rescan_result.unwrap(); let rescan_result = rescan_result.unwrap();
assert_eq!(rescan_result.len(), 3); assert_eq!(rescan_result.len(), 3);
rescan_result rescan_result.into_iter().for_each(|outcome| {
.into_iter() assert!(matches!(
.for_each(|outcome| assert!(matches!(outcome, UpdatePathOutcome::Unchanged(_)))); outcome,
UpdatePathOutcome::Unchanged(_) | UpdatePathOutcome::Skipped(_)
))
});
// Remove a file // Remove a file
std::fs::remove_file(temp_dir.path().join("hello-world.txt")).unwrap(); std::fs::remove_file(temp_dir.path().join("hello-world.txt")).unwrap();
@ -868,12 +873,19 @@ mod test {
let rescan_result = rescan_result.unwrap(); let rescan_result = rescan_result.unwrap();
assert_eq!(rescan_result.len(), 3); assert_eq!(rescan_result.len(), 3);
assert_eq!( assert_eq!(
2, 1,
rescan_result rescan_result
.iter() .iter()
.filter(|upo| matches!(upo, UpdatePathOutcome::Unchanged(_))) .filter(|upo| matches!(upo, UpdatePathOutcome::Unchanged(_)))
.count() .count()
); );
assert_eq!(
1,
rescan_result
.iter()
.filter(|upo| matches!(upo, UpdatePathOutcome::Skipped(_)))
.count()
);
assert_eq!( assert_eq!(
1, 1,
rescan_result rescan_result