[pmg-devel] [PATCH log-tracker] change tests to use faketime
Mira Limbeck
m.limbeck at proxmox.com
Mon Mar 22 14:06:18 CET 2021
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 <m.limbeck at proxmox.com>
---
debian/debcargo.toml | 1 +
tests/tests_after_queue.rs | 24 ++++++++++++-----
tests/tests_before_queue.rs | 52 +++++++++++++++++++++++++++----------
3 files changed, 58 insertions(+), 19 deletions(-)
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")
--
2.20.1
More information about the pmg-devel
mailing list