🐛 fix: replace hardcoded paths in tests with temp directories for CI compatibility

This commit is contained in:
Jeremiah Russell
2025-10-21 12:35:31 +01:00
committed by Jeremiah Russell
parent 8f79081b4f
commit 3dcd229ee9

View File

@@ -334,14 +334,15 @@ mod unit_tests {
#[test] #[test]
fn test_operation_display() { fn test_operation_display() {
let temp_path = std::path::PathBuf::from("/tmp/test"); let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path().join("test");
let create_dir_op = Operation::CreateDir { let create_dir_op = Operation::CreateDir {
path: temp_path.clone(), path: temp_path.clone(),
#[cfg(unix)] #[cfg(unix)]
mode: Some(0o755), mode: Some(0o755),
}; };
assert_eq!(format!("{create_dir_op}"), "Create directory: /tmp/test"); assert_eq!(format!("{create_dir_op}"), format!("Create directory: {}", temp_path.display()));
let copy_file_op = Operation::CopyFile { let copy_file_op = Operation::CopyFile {
from: temp_path.clone(), from: temp_path.clone(),
@@ -352,7 +353,7 @@ mod unit_tests {
}; };
assert_eq!( assert_eq!(
format!("{copy_file_op}"), format!("{copy_file_op}"),
"Copy file: /tmp/test → /tmp/test/dest" format!("Copy file: {}{}", temp_path.display(), temp_path.join("dest").display())
); );
let write_file_op = Operation::WriteFile { let write_file_op = Operation::WriteFile {
@@ -362,7 +363,7 @@ mod unit_tests {
mode: Some(0o644), mode: Some(0o644),
backup_if_exists: false, backup_if_exists: false,
}; };
assert_eq!(format!("{write_file_op}"), "Write file: /tmp/test"); assert_eq!(format!("{write_file_op}"), format!("Write file: {}", temp_path.display()));
let oauth_op = Operation::RunOAuth2 { let oauth_op = Operation::RunOAuth2 {
config_root: "h:.config".to_string(), config_root: "h:.config".to_string(),
@@ -374,7 +375,8 @@ mod unit_tests {
#[cfg(unix)] #[cfg(unix)]
#[test] #[test]
fn test_operation_get_mode() { fn test_operation_get_mode() {
let temp_path = std::path::PathBuf::from("/tmp/test"); let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path().join("test");
let create_dir_op = Operation::CreateDir { let create_dir_op = Operation::CreateDir {
path: temp_path.clone(), path: temp_path.clone(),