Skip to content

Commit 22fa726

Browse files
committed
Add helper function to create test log lines
1 parent 2e7ea84 commit 22fa726

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/auth_file_watcher.test.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::env::temp_dir;
22

3-
use chrono::Local;
4-
53
use crate::auth_file_watcher::AuthFileWatcher;
6-
use crate::test_utils::test_file::{rename_file, TestFile};
4+
use crate::test_utils::test_file::{create_log_line, rename_file, TestFile};
75

86
const TEST_MESSAGES: [&str; 6] = [
97
"workstation sudo: pam_unix(sudo:auth): authentication failure; logname=john uid=1000 euid=0 tty=/dev/pts/7 ruser=john rhost= user=john",
@@ -47,11 +45,6 @@ fn expect_update_callback_is_called_when_file_is_modified(
4745
}
4846
}
4947

50-
fn create_log_line(message: &str) -> String {
51-
let date_time = Local::now().format("%+");
52-
return format!("{} {}\n", date_time, message);
53-
}
54-
5548
#[test]
5649
fn when_more_than_one_line_is_added_then_update_callback_is_called_for_each_line() {
5750
let mut file = TestFile::new("auth-monitor-test");

src/test_utils/test_file.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ pub fn rename_file(filepath: &str, new_filename: &str) {
6262
let new_filepath = new_path.to_str().expect("Unable to build file path");
6363
rename(filepath, new_filepath).expect("Unable to rename test file");
6464
}
65+
66+
pub fn create_log_line(message: &str) -> String {
67+
let date_time = Local::now().format("%+");
68+
return format!("{} {}\n", date_time, message);
69+
}

0 commit comments

Comments
 (0)