Add "node::extract" test; Remove test objects from git;

This commit is contained in:
Nathan Fisher 2023-10-28 19:10:10 -04:00
parent 3b46b11153
commit 5028250a7e
7 changed files with 23 additions and 4 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target
test/
!test/li.txt

View File

@ -319,9 +319,13 @@ mod tests {
fn from_path() {
let links = Mutex::new(HashMap::new());
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
let FileType::Normal(f) = node.filetype else { panic!() };
let FileType::Normal(f) = node.filetype else {
panic!()
};
assert_eq!(f.len, 1005);
let Checksum::Sha256(sum) = f.checksum else { panic!() };
let Checksum::Sha256(sum) = f.checksum else {
panic!()
};
let mut s = String::new();
for c in &sum {
write!(s, "{c:02x}").unwrap();
@ -344,8 +348,12 @@ mod tests {
let fd = std::fs::File::open("test/li.node").unwrap();
let mut reader = BufReader::new(fd);
let node = Node::read(&mut reader).unwrap();
let FileType::Normal(f) = node.filetype else { panic!() };
let Checksum::Sha1(sum) = f.checksum else { panic!() };
let FileType::Normal(f) = node.filetype else {
panic!()
};
let Checksum::Sha1(sum) = f.checksum else {
panic!()
};
let mut s = String::new();
for c in &sum {
write!(s, "{c:02x}").unwrap();
@ -353,4 +361,13 @@ mod tests {
assert_eq!(s, "9bf3e5b5efd22f932e100b86c83482787e82a682");
assert_eq!(LI, f.data);
}
#[test]
fn extract_file() {
let links = Mutex::new(HashMap::new());
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
node.extract(Some("test/output")).unwrap();
let f = fs::read_to_string("test/output/test/li.txt").unwrap();
assert_eq!(f.as_bytes(), LI);
}
}

Binary file not shown.

BIN
test/file

Binary file not shown.

Binary file not shown.

BIN
test/md5

Binary file not shown.

BIN
test/sha1

Binary file not shown.