]> git.proxmox.com Git - pmg-log-tracker.git/blobdiff - tests/tests_before_queue.rs
change tests to use faketime
[pmg-log-tracker.git] / tests / tests_before_queue.rs
index b18cf10cfb3faa36771f744b22c0d35d84d8397d..6089b92b2660aed0d3416c590d6822f841edcb86 100644 (file)
@@ -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")
@@ -16,8 +18,8 @@ fn before_queue_start_end_time_string() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -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")
@@ -37,8 +41,8 @@ fn before_queue_start_end_timestamp() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -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")
@@ -60,8 +66,8 @@ fn before_queue_qid() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue_qid")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue_qid").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -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")
@@ -83,8 +91,8 @@ fn before_queue_host() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue_host")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue_host").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -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")
@@ -114,9 +124,36 @@ fn before_queue_search_string() {
     utils::compare_output(output_reader, expected_output);
 }
 
+#[test]
+fn before_queue_search_string_case_insensitive() {
+    let output = Command::new("faketime")
+        .arg("2020-12-31 23:59:59")
+        .arg(utils::log_tracker_path())
+        .arg("-vv")
+        .arg("-s")
+        .arg("1608300000")
+        .arg("-e")
+        .arg("1608302400")
+        .arg("-i")
+        .arg("tests/test_input_mixed")
+        .arg("-x")
+        .arg("reJECT")
+        .output()
+        .expect("failed to execute pmg-log-tracker");
+
+    let expected_file = File::open("tests/test_output_before_queue_search_string")
+        .expect("failed to open test_output");
+
+    let expected_output = BufReader::new(&expected_file);
+    let output_reader = BufReader::new(&output.stdout[..]);
+    utils::compare_output(output_reader, expected_output);
+}
+
 #[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")
@@ -129,8 +166,8 @@ fn before_queue_exclude_greylist_ndr() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -139,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")
@@ -152,8 +191,8 @@ fn before_queue_to() {
         .output()
         .expect("failed to execute pmg-log-tracker");
 
-    let expected_file = File::open("tests/test_output_before_queue_to")
-        .expect("failed to open test_output");
+    let expected_file =
+        File::open("tests/test_output_before_queue_to").expect("failed to open test_output");
 
     let expected_output = BufReader::new(&expected_file);
     let output_reader = BufReader::new(&output.stdout[..]);
@@ -162,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")
@@ -183,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")
@@ -205,3 +248,77 @@ fn before_queue_from_to() {
     let output_reader = BufReader::new(&output.stdout[..]);
     utils::compare_output(output_reader, expected_output);
 }
+
+#[test]
+fn before_queue_mixed_accept_block_quarantine() {
+    let output = Command::new("faketime")
+        .arg("2020-12-31 23:59:59")
+        .arg(utils::log_tracker_path())
+        .arg("-vv")
+        .arg("-s")
+        .arg("1588254000")
+        .arg("-e")
+        .arg("1588255200")
+        .arg("-i")
+        .arg("tests/test_input_mixed_accept_block_quarantine")
+        .arg("-n")
+        .output()
+        .expect("failed to execute pmg-log-tracker");
+
+    let expected_file = File::open("tests/test_output_before_queue_mixed_accept_block_quarantine")
+        .expect("failed to open test_output");
+
+    let expected_output = BufReader::new(&expected_file);
+    let output_reader = BufReader::new(&output.stdout[..]);
+    utils::compare_output(output_reader, expected_output);
+}
+
+#[test]
+fn before_queue_to_search_string() {
+    let output = Command::new("faketime")
+        .arg("2020-12-31 23:59:59")
+        .arg(utils::log_tracker_path())
+        .arg("-vv")
+        .arg("-s")
+        .arg("1589810100")
+        .arg("-e")
+        .arg("1589812000")
+        .arg("-i")
+        .arg("tests/test_input_before_queue_to_search_string")
+        .arg("-t")
+        .arg("ferdl@example.proxmox.com")
+        .arg("-x")
+        .arg("ferdl@example.proxmox.com")
+        .output()
+        .expect("failed to execute pmg-log-tracker");
+
+    let expected_file = File::open("tests/test_output_before_queue_to_search_string")
+        .expect("failed to open test_output");
+
+    let expected_output = BufReader::new(&expected_file);
+    let output_reader = BufReader::new(&output.stdout[..]);
+    utils::compare_output(output_reader, expected_output);
+}
+
+#[test]
+fn before_queue_syntax_reject() {
+    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")
+        .arg("-e")
+        .arg("2020-08-27 14:05:00")
+        .arg("-i")
+        .arg("tests/test_input_before_queue_syntax_reject")
+        .output()
+        .expect("failed to execute pmg-log-tracker");
+
+    let expected_file = File::open("tests/test_output_before_queue_syntax_reject")
+        .expect("failed to open test_output");
+
+    let expected_output = BufReader::new(&expected_file);
+    let output_reader = BufReader::new(&output.stdout[..]);
+    utils::compare_output(output_reader, expected_output);
+}