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
|
/target
|
||||||
|
test/
|
||||||
|
!test/li.txt
|
||||||
|
25
src/node.rs
25
src/node.rs
@ -319,9 +319,13 @@ mod tests {
|
|||||||
fn from_path() {
|
fn from_path() {
|
||||||
let links = Mutex::new(HashMap::new());
|
let links = Mutex::new(HashMap::new());
|
||||||
let node = Node::from_path("test/li.txt", Algorithm::Sha256, &links).unwrap();
|
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);
|
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();
|
let mut s = String::new();
|
||||||
for c in &sum {
|
for c in &sum {
|
||||||
write!(s, "{c:02x}").unwrap();
|
write!(s, "{c:02x}").unwrap();
|
||||||
@ -344,8 +348,12 @@ mod tests {
|
|||||||
let fd = std::fs::File::open("test/li.node").unwrap();
|
let fd = std::fs::File::open("test/li.node").unwrap();
|
||||||
let mut reader = BufReader::new(fd);
|
let mut reader = BufReader::new(fd);
|
||||||
let node = Node::read(&mut reader).unwrap();
|
let node = Node::read(&mut reader).unwrap();
|
||||||
let FileType::Normal(f) = node.filetype else { panic!() };
|
let FileType::Normal(f) = node.filetype else {
|
||||||
let Checksum::Sha1(sum) = f.checksum else { panic!() };
|
panic!()
|
||||||
|
};
|
||||||
|
let Checksum::Sha1(sum) = f.checksum else {
|
||||||
|
panic!()
|
||||||
|
};
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
for c in &sum {
|
for c in &sum {
|
||||||
write!(s, "{c:02x}").unwrap();
|
write!(s, "{c:02x}").unwrap();
|
||||||
@ -353,4 +361,13 @@ mod tests {
|
|||||||
assert_eq!(s, "9bf3e5b5efd22f932e100b86c83482787e82a682");
|
assert_eq!(s, "9bf3e5b5efd22f932e100b86c83482787e82a682");
|
||||||
assert_eq!(LI, f.data);
|
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