Add "node::extract" test; Remove test objects from git;
This commit is contained in:
parent
3b46b11153
commit
5028250a7e
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/target
|
||||
test/
|
||||
!test/li.txt
|
||||
|
25
src/node.rs
25
src/node.rs
@ -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);
|
||||
}
|
||||
}
|
||||
|
BIN
test/device
BIN
test/device
Binary file not shown.
BIN
test/li.node
BIN
test/li.node
Binary file not shown.
Loading…
Reference in New Issue
Block a user