Skip to content

Commit

Permalink
add simpler integration test for mactime2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Starke committed Sep 22, 2023
1 parent 82f3330 commit 9d2838c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
39 changes: 13 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ matches = "0.1"
# es4forensics
assert-json-diff = "2.0"

assert_cmd = "1"
assert_cmd = "2"
2 changes: 1 addition & 1 deletion tests/mactime2/autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fn test_zsh() {
fn test_fish() {
let mut cmd = Command::cargo_bin("mactime2").unwrap();
cmd.arg("--autocomplete").arg("fish").assert().success();
}
}
29 changes: 29 additions & 0 deletions tests/mactime2/is_sorted.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::{path::PathBuf, io::{BufReader, Cursor, BufRead}};

use assert_cmd::Command;
use more_asserts::assert_le;

#[test]
fn is_sorted() {
let mut cmd = Command::cargo_bin("mactime2").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("mactime2");
data_path.push("sample.bodyfile");

let result = cmd.arg("-d").arg("-b").arg(data_path).ok();
assert!(result.is_ok());

let reader = BufReader::new(Cursor::new(result.unwrap().stdout));
let mut previous_line = None;
for line in reader.lines().map_while(Result::ok) {
let comma_index = line.find(',').unwrap();
assert_eq!(comma_index, "2022-04-18T10:28:59+00:00".len());
let timestamp = line[..comma_index].to_owned();
if let Some(pv) = previous_line {
assert_le!(pv, timestamp);
}
previous_line = Some(timestamp);
}
}
3 changes: 2 additions & 1 deletion tests/mactime2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod help;
mod autocomplete;
mod autocomplete;
mod is_sorted;

0 comments on commit 9d2838c

Please sign in to comment.