diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-09-25 15:49:28 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-09-25 15:49:28 +0800 |
| commit | 0eeb842c21ff1681e77ccbd47fe7a3c9779a65d5 (patch) | |
| tree | 8c3ffb1f97dbbedb7756fb33f519547083047f24 /crates/vcs | |
| parent | 2865206dda1d57df1c95dd8e49d5599db89407ae (diff) | |
Fix clippy warnings in test files
- Convert manual async functions to async fn syntax
- Replace assert_eq!(true/false, ...) with assert!(...) and assert!(!...)
- Fix useless vec warning by using array directly
- All tests continue to pass after optimizations
Diffstat (limited to 'crates/vcs')
| -rw-r--r-- | crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs | 12 | ||||
| -rw-r--r-- | crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs | 154 |
2 files changed, 78 insertions, 88 deletions
diff --git a/crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs b/crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs index 85b473b..ced027d 100644 --- a/crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs +++ b/crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs @@ -49,20 +49,18 @@ async fn test_vault_setup_and_member_register() -> Result<(), std::io::Error> { const ID_PARAM: &str = "{member_id}"; // Check if the member info file exists - assert_eq!( + assert!( dir.join(SERVER_FILE_MEMBER_INFO.replace(ID_PARAM, member_id)) - .exists(), - true + .exists() ); // Remove member vault.remove_member_from_vault(&member_id.to_string())?; // Check if the member info file not exists - assert_eq!( - dir.join(SERVER_FILE_MEMBER_INFO.replace(ID_PARAM, member_id)) - .exists(), - false + assert!( + !dir.join(SERVER_FILE_MEMBER_INFO.replace(ID_PARAM, member_id)) + .exists() ); Ok(()) diff --git a/crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs b/crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs index d2a2e44..bfcf817 100644 --- a/crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs +++ b/crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs @@ -24,94 +24,86 @@ struct VirtualFileCreateClientHandle; struct VirtualFileCreateServerHandle; impl ClientHandle<VirtualFileCreateServerHandle> for VirtualFileCreateClientHandle { - fn process( - mut instance: tcp_connection::instance::ConnectionInstance, - ) -> impl Future<Output = ()> + Send { - async move { - let dir = get_test_dir("virtual_file_creation_and_update_2") - .await - .unwrap(); - // Create first test file for virtual file creation - let test_content_1 = b"Test file content for virtual file creation"; - let temp_file_path_1 = dir.join("test_virtual_file_1.txt"); - - tokio::fs::write(&temp_file_path_1, test_content_1) - .await - .unwrap(); - - // Send the first file to server for virtual file creation - instance.write_file(&temp_file_path_1).await.unwrap(); - - // Create second test file for virtual file update - let test_content_2 = b"Updated test file content for virtual file"; - let temp_file_path_2 = dir.join("test_virtual_file_2.txt"); - - tokio::fs::write(&temp_file_path_2, test_content_2) - .await - .unwrap(); - - // Send the second file to server for virtual file update - instance.write_file(&temp_file_path_2).await.unwrap(); - } + async fn process(mut instance: tcp_connection::instance::ConnectionInstance) { + let dir = get_test_dir("virtual_file_creation_and_update_2") + .await + .unwrap(); + // Create first test file for virtual file creation + let test_content_1 = b"Test file content for virtual file creation"; + let temp_file_path_1 = dir.join("test_virtual_file_1.txt"); + + tokio::fs::write(&temp_file_path_1, test_content_1) + .await + .unwrap(); + + // Send the first file to server for virtual file creation + instance.write_file(&temp_file_path_1).await.unwrap(); + + // Create second test file for virtual file update + let test_content_2 = b"Updated test file content for virtual file"; + let temp_file_path_2 = dir.join("test_virtual_file_2.txt"); + + tokio::fs::write(&temp_file_path_2, test_content_2) + .await + .unwrap(); + + // Send the second file to server for virtual file update + instance.write_file(&temp_file_path_2).await.unwrap(); } } impl ServerHandle<VirtualFileCreateClientHandle> for VirtualFileCreateServerHandle { - fn process( - mut instance: tcp_connection::instance::ConnectionInstance, - ) -> impl Future<Output = ()> + Send { - async move { - let dir = get_test_dir("virtual_file_creation_and_update") - .await - .unwrap(); - - // Setup vault - Vault::setup_vault(dir.clone()).await.unwrap(); - - // Read vault - let Some(vault) = Vault::init( - VaultConfig::read_from(dir.join(SERVER_FILE_VAULT)) - .await - .unwrap(), - &dir, - ) else { - panic!("No vault found!"); - }; - - // Register member - let member_id = "test_member"; - vault - .register_member_to_vault(Member::new(member_id)) - .await - .unwrap(); + async fn process(mut instance: tcp_connection::instance::ConnectionInstance) { + let dir = get_test_dir("virtual_file_creation_and_update") + .await + .unwrap(); - // Create visual file - let virtual_file_id = vault - .create_virtual_file_from_connection(&mut instance, &member_id.to_string()) - .await - .unwrap(); + // Setup vault + Vault::setup_vault(dir.clone()).await.unwrap(); - // Grant edit right to member - vault - .grant_virtual_file_edit_right(&member_id.to_string(), &virtual_file_id) - .await - .unwrap(); - - // Update visual file - vault - .update_virtual_file_from_connection( - &mut instance, - &member_id.to_string(), - &virtual_file_id, - &"2".to_string(), - VirtualFileVersionDescription { - creator: member_id.to_string(), - description: "Update".to_string(), - }, - ) + // Read vault + let Some(vault) = Vault::init( + VaultConfig::read_from(dir.join(SERVER_FILE_VAULT)) .await - .unwrap(); - } + .unwrap(), + &dir, + ) else { + panic!("No vault found!"); + }; + + // Register member + let member_id = "test_member"; + vault + .register_member_to_vault(Member::new(member_id)) + .await + .unwrap(); + + // Create visual file + let virtual_file_id = vault + .create_virtual_file_from_connection(&mut instance, &member_id.to_string()) + .await + .unwrap(); + + // Grant edit right to member + vault + .grant_virtual_file_edit_right(&member_id.to_string(), &virtual_file_id) + .await + .unwrap(); + + // Update visual file + vault + .update_virtual_file_from_connection( + &mut instance, + &member_id.to_string(), + &virtual_file_id, + &"2".to_string(), + VirtualFileVersionDescription { + creator: member_id.to_string(), + description: "Update".to_string(), + }, + ) + .await + .unwrap(); } } |
