Skip to content

Commit

Permalink
tests: add test case to verify tempdir extraction is fixed
Browse files Browse the repository at this point in the history
Closes #34
  • Loading branch information
muja committed Aug 28, 2024
1 parent 801318a commit 519956a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ widestring = "1"
[dependencies.unrar_sys]
path = "unrar_sys"
version = "0.3"

[dev-dependencies]
tempfile = "3.12.0"
16 changes: 16 additions & 0 deletions tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ fn version_cat() {
let s = String::from_utf8(bytes).unwrap();
assert_eq!(s, "unrar-0.4.0");
}

#[test]
fn extract_to_tempdir() {
// see https://github.com/muja/unrar.rs/issues/34
let file = "data/version.rar".to_owned();
let mut archive = unrar::Archive::new(&file).open_for_processing().expect("open archive");
let temp_path = tempfile::tempdir().expect("creating tempdir");
let temp_path = temp_path.path();
while let Some(header) = archive.read_header().expect("read header") {
let temp_file_path = temp_path.join(header.entry().filename.as_path());
archive = header.extract_to(temp_file_path.as_path()).expect("extract_to");
}
let entries = std::fs::read_dir(&temp_path).expect("read tempdir").collect::<Result<Vec<_>, _>>().unwrap();
assert!(entries.len() == 1);
assert!(entries[0].file_name() == "VERSION");
}

0 comments on commit 519956a

Please sign in to comment.