Skip to content

Commit 1fd9a10

Browse files
committed
Move rename_file() to test_utilsL::TestFile
1 parent d922a26 commit 1fd9a10

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/auth_file_watcher.test.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use std::env::temp_dir;
2-
use std::fs::rename;
3-
use std::path::Path;
42

53
use chrono::Local;
64

75
use crate::auth_file_watcher::AuthFileWatcher;
8-
use crate::test_utils::test_file::TestFile;
6+
use crate::test_utils::test_file::{rename_file, TestFile};
97

108
const AUTH_FAILED_MESSAGES: [&str; 6] = [
119
"workstation sudo: pam_unix(sudo:auth): authentication failure; logname=john uid=1000 euid=0 tty=/dev/pts/7 ruser=john rhost= user=john",
@@ -118,16 +116,6 @@ fn when_new_file_has_been_created_after_old_was_renamed_then_changes_in_new_file
118116
expect_update_callback_is_called_when_file_is_modified(&mut file, &mut auth_file_watcher);
119117
}
120118

121-
fn rename_file(filepath: &str, new_filename: &str) {
122-
println!("Renaming test file {} to {}", filepath, new_filename);
123-
let new_path = Path::new(&filepath)
124-
.parent()
125-
.expect("Unable to get directory")
126-
.join(new_filename);
127-
let new_filepath = new_path.to_str().expect("Unable to build file path");
128-
rename(filepath, new_filepath).expect("Unable to rename test file");
129-
}
130-
131119
#[test]
132120
fn when_monitored_file_has_been_truncated_then_changes_are_still_monitored() {
133121
let mut file = TestFile::new("auth-monitor-test");

src/test_utils/test_file.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env::temp_dir;
2-
use std::fs::{remove_file, File};
2+
use std::fs::{remove_file, rename, File};
33
use std::io::Write;
4+
use std::path::Path;
45

56
use chrono::Local;
67

@@ -51,3 +52,13 @@ impl Drop for TestFile {
5152
self.remove();
5253
}
5354
}
55+
56+
pub fn rename_file(filepath: &str, new_filename: &str) {
57+
println!("Renaming test file {} to {}", filepath, new_filename);
58+
let new_path = Path::new(&filepath)
59+
.parent()
60+
.expect("Unable to get directory")
61+
.join(new_filename);
62+
let new_filepath = new_path.to_str().expect("Unable to build file path");
63+
rename(filepath, new_filepath).expect("Unable to rename test file");
64+
}

0 commit comments

Comments
 (0)