From ef4e4370a3a7a13eead0a5b3c4bed44f654f5b5b Mon Sep 17 00:00:00 2001 From: Mira Limbeck Date: Mon, 22 Mar 2021 14:06:18 +0100 Subject: [PATCH] change tests to use faketime We only have the month, day, hours, minutes and seconds available to us, but not the year. Because of this we assume the logs are always relative to the current year. This means when running the log tracker the CTIME is calculated based on the current year and once a new year starts, all old tests have to be updated to match the new year. To work around this issue, use 'faketime' to set the time to 2020-12-31 23:59:59 as all tests assume 2020 as the year. Signed-off-by: Mira Limbeck Signed-off-by: Stoiko Ivanov --- debian/control | 3 ++- debian/debcargo.toml | 1 + tests/tests_after_queue.rs | 24 ++++++++++++----- tests/tests_before_queue.rs | 52 +++++++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/debian/control b/debian/control index 44c2adc..18d361a 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,8 @@ Build-Depends: debhelper (>= 11), librust-failure-0.1+default-dev (>= 0.1.5-~~), librust-flate2-1+default-dev (>= 1.0.6-~~), librust-libc-0.2+default-dev (>= 0.2.48-~~), - librust-time-0.1+default-dev (>= 0.1.42-~~) + librust-time-0.1+default-dev (>= 0.1.42-~~), + faketime Maintainer: Proxmox Support Team Standards-Version: 4.4.1 Vcs-Git: git://git.proxmox.com/git/pmg-log-tracker.git diff --git a/debian/debcargo.toml b/debian/debcargo.toml index 5ee9490..3a5c8a0 100644 --- a/debian/debcargo.toml +++ b/debian/debcargo.toml @@ -7,6 +7,7 @@ section = "admin" homepage = "http://www.proxmox.com" vcs_git = "git://git.proxmox.com/git/pmg-log-tracker.git" vcs_browser = "https://git.proxmox.com/?p=pmg-log-tracker.git;a=summary" +build_depends = ["faketime"] [package] summary = "Proxmox Mailgateway Log Tracker" diff --git a/tests/tests_after_queue.rs b/tests/tests_after_queue.rs index f479325..6918de7 100644 --- a/tests/tests_after_queue.rs +++ b/tests/tests_after_queue.rs @@ -6,7 +6,9 @@ mod utils; #[test] fn after_queue_start_end_time_string() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("2020-12-18 15:40:00") @@ -27,7 +29,9 @@ fn after_queue_start_end_time_string() { #[test] fn after_queue_start_end_timestamp() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608302400") @@ -48,7 +52,9 @@ fn after_queue_start_end_timestamp() { #[test] fn after_queue_qid() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608302400") @@ -71,7 +77,9 @@ fn after_queue_qid() { #[test] fn after_queue_host() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608302400") @@ -94,7 +102,9 @@ fn after_queue_host() { #[test] fn after_queue_search_string() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608302400") @@ -117,7 +127,9 @@ fn after_queue_search_string() { #[test] fn after_queue_search_string_case_insensitive() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608302400") diff --git a/tests/tests_before_queue.rs b/tests/tests_before_queue.rs index 5f36ec2..6089b92 100644 --- a/tests/tests_before_queue.rs +++ b/tests/tests_before_queue.rs @@ -5,7 +5,9 @@ mod utils; #[test] fn before_queue_start_end_time_string() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("2020-12-18 15:00:00") @@ -26,7 +28,9 @@ fn before_queue_start_end_time_string() { #[test] fn before_queue_start_end_timestamp() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -47,7 +51,9 @@ fn before_queue_start_end_timestamp() { #[test] fn before_queue_qid() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -70,7 +76,9 @@ fn before_queue_qid() { #[test] fn before_queue_host() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -93,7 +101,9 @@ fn before_queue_host() { #[test] fn before_queue_search_string() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -116,7 +126,9 @@ fn before_queue_search_string() { #[test] fn before_queue_search_string_case_insensitive() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -139,7 +151,9 @@ fn before_queue_search_string_case_insensitive() { #[test] fn before_queue_exclude_greylist_ndr() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -162,7 +176,9 @@ fn before_queue_exclude_greylist_ndr() { #[test] fn before_queue_to() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -185,7 +201,9 @@ fn before_queue_to() { #[test] fn before_queue_mixed_downstream() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-v") .arg("-s") .arg("1608303600") @@ -206,7 +224,9 @@ fn before_queue_mixed_downstream() { #[test] fn before_queue_from_to() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1608300000") @@ -231,7 +251,9 @@ fn before_queue_from_to() { #[test] fn before_queue_mixed_accept_block_quarantine() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1588254000") @@ -253,7 +275,9 @@ fn before_queue_mixed_accept_block_quarantine() { #[test] fn before_queue_to_search_string() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("1589810100") @@ -278,7 +302,9 @@ fn before_queue_to_search_string() { #[test] fn before_queue_syntax_reject() { - let output = Command::new(utils::log_tracker_path()) + let output = Command::new("faketime") + .arg("2020-12-31 23:59:59") + .arg(utils::log_tracker_path()) .arg("-vv") .arg("-s") .arg("2020-08-27 14:00:00")