-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macos|rust] Add mountpoint test that perform a copy using finder.app
Closes #9366
- Loading branch information
1 parent
433d485
commit 8300305
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libparsec/crates/platform_mountpoint/scripts/macos/copy-using-finder.scpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
42 changes: 42 additions & 0 deletions
42
libparsec/crates/platform_mountpoint/tests/unit/operations/macos/copy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
libparsec/crates/platform_mountpoint/tests/unit/operations/macos/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod copy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters