From fc62c62dcc7cf327c55a189ff464c555acc1f760 Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sun, 10 Nov 2024 20:48:46 +0000 Subject: [PATCH] =?UTF-8?q?fix(ssg):=20=F0=9F=8E=A8=20added=20new=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/process.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/process.rs b/src/process.rs index c72ccb88..b049d6a7 100644 --- a/src/process.rs +++ b/src/process.rs @@ -335,4 +335,74 @@ mod tests { assert!(matches!(error, ProcessError::IoError(_))); assert_eq!(error.to_string(), "File not found"); } + + #[test] + fn test_ensure_directory_permission_denied() { + use std::fs::Permissions; + use std::os::unix::fs::PermissionsExt; + + let temp_dir = tempdir().unwrap(); + let protected_path = temp_dir.path().join("protected_dir"); + + // Create the directory and make it read-only + fs::create_dir(&protected_path).unwrap(); + fs::set_permissions( + &protected_path, + Permissions::from_mode(0o400), + ) + .unwrap(); + + // Attempt to create a subdirectory inside the protected directory to trigger a permission error + let sub_dir = protected_path.join("sub_dir"); + let result = ensure_directory(&sub_dir, "sub_directory"); + + // Check that the permission-denied error was triggered + assert!(matches!( + result, + Err(ProcessError::DirectoryCreation { .. }) + )); + + // Reset permissions for cleanup + fs::set_permissions( + &protected_path, + Permissions::from_mode(0o700), + ) + .unwrap(); + } + + #[test] + fn test_args_all_required_arguments( + ) -> Result<(), Box> { + let temp_dir = tempdir()?; + let content_dir = temp_dir.path().join("content"); + let output_dir = temp_dir.path().join("output"); + let site_dir = temp_dir.path().join("new_site"); + let template_dir = temp_dir.path().join("template"); + + let matches = Command::new("test") + .arg(arg!(--"content" "Content directory")) + .arg(arg!(--"output" "Output directory")) + .arg(arg!(--"new" "New site directory")) + .arg(arg!(--"template"