Skip to content

Commit

Permalink
[macos|rust] Add mountpoint test that perform a copy using finder.app
Browse files Browse the repository at this point in the history
Closes #9366
  • Loading branch information
FirelightFlagboy committed Jan 21, 2025
1 parent 433d485 commit 8300305
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libparsec/crates/platform_mountpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env_logger = { workspace = true }
libparsec_client_connection = { workspace = true }
libparsec_tests_fixtures = { workspace = true, features = ["default"] }
libparsec_tests_lite = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
tokio = { workspace = true, features = ["fs", "process"] }
windows-sys = { workspace = true, features = ["Win32"] }

[target.'cfg(target_family = "unix")'.dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/osascript

on run argv
try
-- Get file and dest path from arguments
set file_path to item 1 of argv
set dest_path to item 2 of argv

-- Use Finder to copy the file to dest
tell application "Finder"
set source_file to POSIX file file_path as alias
set destination_folder to POSIX file dest_path as alias
duplicate source_file to destination_folder
end tell

on error err_msg number err_num
-- Print error message to stderr
do shell script "echo " & quoted form of ("Error: " & err_msg) & " >&2"
return err_num
end try
end run


Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::path::PathBuf;

use libparsec_tests_fixtures::{tmp_path, TestbedEnv, TmpPath};
use libparsec_tests_lite::parsec_test;

use crate::operations::utils::mount_and_test;

#[parsec_test(testbed = "minimal_client_ready")]
async fn copy_file_using_finder(tmp_path: TmpPath, env: &TestbedEnv) {
mount_and_test!(
env,
&tmp_path,
|_client, _wksp_ops, mountpoint_path: PathBuf| async move {
const FILE_CONTENT: &str = "I'm the file content that should be copied";
let src_file = tmp_path.join("foo.txt");
let dst_file = mountpoint_path.join("foo.txt");
let script_path = std::path::PathBuf::from(std::env!("CARGO_MANIFEST_DIR"))
.join("scripts/macos/copy-using-finder.scpt");

assert!(
!tokio::fs::try_exists(&dst_file).await.unwrap(),
"The destination file should not exist before the copy"
);

// Create the source file with some content
tokio::fs::write(&src_file, FILE_CONTENT).await.unwrap();

// Call the osascript that perform the copy using Finder.app
tokio::process::Command::new("osascript")
.args([&script_path, &src_file, &dst_file])
.spawn()
.unwrap()
.wait()
.await
.unwrap();

// Verify the content of the copied file
let data = tokio::fs::read_to_string(&dst_file).await.unwrap();
assert_eq!(data, FILE_CONTENT);
}
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod copy;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
mod create_folder;
mod flush_file;
mod list_directory;
#[cfg(target_os = "macos")]
mod macos;
mod mount_unmount;
mod move_entry;
mod open_file;
Expand Down

0 comments on commit 8300305

Please sign in to comment.