[wip] unit tests for file module

- testing for `Checked`
This commit is contained in:
Jörn-Michael Miehe 2025-07-04 17:13:48 +00:00
parent 95dcc25e0d
commit 1ac110ddfb

View file

@ -137,6 +137,13 @@ mod tests {
assert_eq!(chk.path, path); assert_eq!(chk.path, path);
assert_eq!(chk.size, size); assert_eq!(chk.size, size);
assert!(chk.hash.is_none()); assert!(chk.hash.is_none());
// `FileTrait`
assert_eq!(
chk.get_name(),
file.path().file_name().expect("`file_name` should succeed")
);
assert_eq!(chk.get_size(), size);
} }
} }
@ -174,7 +181,9 @@ mod tests {
let file = create_file(content); let file = create_file(content);
let mut chk = Checked::new(file.path()).expect("creating `Checked` should succeed"); let mut chk = Checked::new(file.path()).expect("creating `Checked` should succeed");
chk.hash(drop).expect("hashing should succeed"); chk.hash(drop).expect("`hash` should succeed");
chk.check_hash(drop).expect("`check_hash` should succeed");
assert_eq!(chk.hash, Some(hash.to_string())); assert_eq!(chk.hash, Some(hash.to_string()));
} }
} }
@ -185,8 +194,8 @@ mod tests {
let file = create_file(content); let file = create_file(content);
let mut chk = Checked::new(file.path()).expect("creating `Checked` should succeed"); let mut chk = Checked::new(file.path()).expect("creating `Checked` should succeed");
chk.hash(drop).expect("hashing should succeed"); chk.hash(drop).expect("`hash` should succeed");
let err = chk.hash(drop).expect_err("hashing twice should fail"); let err = chk.hash(drop).expect_err("`hash` twice should fail");
assert!(err.is_mismatch("unhashed file", chk.path.display().to_string())); assert!(err.is_mismatch("unhashed file", chk.path.display().to_string()));
} }