From 5289cf7d9831ff496e6ba4d6732774d9641fb288 Mon Sep 17 00:00:00 2001 From: Jan Starke Date: Mon, 25 Sep 2023 11:01:39 +0200 Subject: [PATCH] add integration tests for ts2date --- tests/mod.rs | 3 +- tests/ts2date.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/ts2date.rs diff --git a/tests/mod.rs b/tests/mod.rs index c73323e..9d99919 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1 +1,2 @@ -mod mactime2; \ No newline at end of file +mod mactime2; +mod ts2date; \ No newline at end of file diff --git a/tests/ts2date.rs b/tests/ts2date.rs new file mode 100644 index 0000000..ea39b4e --- /dev/null +++ b/tests/ts2date.rs @@ -0,0 +1,72 @@ +use assert_cmd::Command; + +const SAMPLE_TIMELINE: &str = r#"1693411717|REG|||App Paths - protocolhandler.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\protocolhandler.exe +1693411717|REG|||App Paths - sdxhelper.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SDXHelper.exe +1693411717|REG|||App Paths - selfcert.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SELFCERT.exe +1693411581|REG|||App Paths - msaccess.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Access_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\MSACCESS.exe"#; + +#[test] +fn ts2date_simple() { + const SAMPLE_TIMELINE_OUT: &str = r#"2023-08-30T16:08:37+00:00|REG|||App Paths - protocolhandler.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\protocolhandler.exe +2023-08-30T16:08:37+00:00|REG|||App Paths - sdxhelper.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SDXHelper.exe +2023-08-30T16:08:37+00:00|REG|||App Paths - selfcert.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SELFCERT.exe +2023-08-30T16:06:21+00:00|REG|||App Paths - msaccess.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Access_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\MSACCESS.exe +"#; + + let mut cmd = Command::cargo_bin("ts2date").unwrap(); + let result = cmd.write_stdin(SAMPLE_TIMELINE).ok(); + assert!(result.is_ok()); + + assert_eq!( + SAMPLE_TIMELINE_OUT, + String::from_utf8(result.unwrap().stdout).unwrap() + ); +} + +#[test] +fn ts2date_utc2berlin() { + const SAMPLE_TIMELINE_OUT: &str = r#"2023-08-30T18:08:37+02:00|REG|||App Paths - protocolhandler.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\protocolhandler.exe +2023-08-30T18:08:37+02:00|REG|||App Paths - sdxhelper.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SDXHelper.exe +2023-08-30T18:08:37+02:00|REG|||App Paths - selfcert.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SELFCERT.exe +2023-08-30T18:06:21+02:00|REG|||App Paths - msaccess.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Access_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\MSACCESS.exe +"#; + + let mut cmd = Command::cargo_bin("ts2date").unwrap(); + let result = cmd + .arg("-f") + .arg("UTC") + .arg("-t") + .arg("Europe/Berlin") + .write_stdin(SAMPLE_TIMELINE) + .ok(); + assert!(result.is_ok()); + + assert_eq!( + SAMPLE_TIMELINE_OUT, + String::from_utf8(result.unwrap().stdout).unwrap() + ); +} + +#[test] +fn ts2date_berlin2utc() { + const SAMPLE_TIMELINE_OUT: &str = r#"2023-08-30T14:08:37+00:00|REG|||App Paths - protocolhandler.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\protocolhandler.exe +2023-08-30T14:08:37+00:00|REG|||App Paths - sdxhelper.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SDXHelper.exe +2023-08-30T14:08:37+00:00|REG|||App Paths - selfcert.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\SELFCERT.exe +2023-08-30T14:06:21+00:00|REG|||App Paths - msaccess.exe - C:\Program Files\WindowsApps\Microsoft.Office.Desktop.Access_16051.16626.20170.0_x86__8wekyb3d8bbwe\Office16\MSACCESS.exe +"#; + + let mut cmd = Command::cargo_bin("ts2date").unwrap(); + let result = cmd + .arg("-f") + .arg("Europe/Berlin") + .arg("-t") + .arg("UTC") + .write_stdin(SAMPLE_TIMELINE) + .ok(); + assert!(result.is_ok()); + + assert_eq!( + SAMPLE_TIMELINE_OUT, + String::from_utf8(result.unwrap().stdout).unwrap() + ); +}