51 lines
1.9 KiB
Rust
51 lines
1.9 KiB
Rust
|
use std::fs;
|
||
|
use std::path::PathBuf;
|
||
|
use tempdir::TempDir;
|
||
|
|
||
|
#[test]
|
||
|
fn test_unpack_simple() {
|
||
|
let unpack_dir = TempDir::new("ark_unpack").unwrap();
|
||
|
ark::unpack("tests/samples/simple.tar.gz", unpack_dir.path()).unwrap();
|
||
|
let unpack_path = unpack_dir.path().join("tests/samples/simple");
|
||
|
compare_trees("tests/samples/simple".into(), unpack_path);
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn test_unpack_symlinks() {
|
||
|
let unpack_dir = TempDir::new("ark_unpack").unwrap();
|
||
|
ark::unpack("tests/samples/symlinks.tar.gz", unpack_dir.path()).unwrap();
|
||
|
let unpack_path = unpack_dir.path().join("tests/samples/symlinks");
|
||
|
compare_trees("tests/samples/symlinks".into(), unpack_path);
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
fn test_unpack_bz2() {
|
||
|
let unpack_dir = TempDir::new("ark_unpack").unwrap();
|
||
|
ark::unpack("tests/samples/simple.tar.bz2", unpack_dir.path()).unwrap();
|
||
|
let unpack_path = unpack_dir.path().join("tests/samples/simple");
|
||
|
compare_trees("tests/samples/simple".into(), unpack_path);
|
||
|
}
|
||
|
|
||
|
fn compare_trees(src: PathBuf, dst: PathBuf) {
|
||
|
// we don't want to follow symlinks, because if the symlink points
|
||
|
// within the archive then we'll be looking at it anyway, and if
|
||
|
// points outside then it's out of scope for us
|
||
|
let src_meta = src.symlink_metadata().unwrap();
|
||
|
let dst_meta = dst.symlink_metadata().unwrap();
|
||
|
assert_eq!(src_meta.file_type(), dst_meta.file_type());
|
||
|
assert_eq!(src_meta.permissions(), dst_meta.permissions());
|
||
|
if src_meta.is_symlink() {
|
||
|
let src_target = fs::read_link(&src).unwrap();
|
||
|
let dst_target = fs::read_link(&dst).unwrap();
|
||
|
assert_eq!(src_target, dst_target);
|
||
|
}
|
||
|
// eventually compare content of files here
|
||
|
else if src_meta.is_dir() {
|
||
|
for entry in fs::read_dir(&src).unwrap() {
|
||
|
let src_child = entry.unwrap().path();
|
||
|
let dst_child = dst.join(src_child.file_name().unwrap());
|
||
|
compare_trees(src_child, dst_child);
|
||
|
}
|
||
|
}
|
||
|
}
|