-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test for zip2bodyfile
- Loading branch information
Showing
5 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod mactime2; | ||
mod ts2date; | ||
mod lnk2bodyfile; | ||
mod lnk2bodyfile; | ||
mod zip2bodyfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::{ | ||
io::{BufRead, BufReader, Cursor}, | ||
path::PathBuf, | ||
}; | ||
|
||
use assert_cmd::Command; | ||
use dfir_toolkit::common::bodyfile::{Bodyfile3Line, Accessed, Modified, Changed, Created}; | ||
|
||
#[test] | ||
fn test_hello() { | ||
do_test_hello(r#"hello.txt"#, vec![].into_iter()); | ||
} | ||
|
||
#[test] | ||
fn test_hello_with_archive_name() { | ||
do_test_hello(r#"hello.txt (in archive hello.zip)"#, vec!["--show-archive-name"].into_iter()); | ||
} | ||
|
||
fn do_test_hello(expected_name: &str, args: impl Iterator<Item = &'static str>) { | ||
let mut cmd = Command::cargo_bin("zip2bodyfile").unwrap(); | ||
let mut data_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
data_path.push("tests"); | ||
data_path.push("data"); | ||
data_path.push("zip2bodyfile"); | ||
data_path.push("hello.zip"); | ||
|
||
let result = cmd.arg(data_path).args(args).ok(); | ||
if result.is_err() { | ||
println!("{}", result.as_ref().err().unwrap()); | ||
} | ||
|
||
assert!(result.is_ok()); | ||
|
||
// parse the result as bodyfile 😈 | ||
let reader = BufReader::new(Cursor::new(result.unwrap().stdout)); | ||
let mut lines_iterator = reader.lines(); | ||
let first_line = lines_iterator.next().unwrap().unwrap(); | ||
|
||
let bfline = Bodyfile3Line::try_from(&first_line[..]).unwrap(); | ||
assert_eq!(bfline.get_name(), expected_name); | ||
assert_eq!(*bfline.get_size(), 12); | ||
assert_eq!(*bfline.get_atime(), Accessed::default()); | ||
assert_eq!(*bfline.get_mtime(), Modified::from(1709197630)); | ||
assert_eq!(*bfline.get_ctime(), Changed::default()); | ||
assert_eq!(*bfline.get_crtime(), Created::default()); | ||
|
||
assert!(lines_iterator.next().is_none()); | ||
} |