summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-09-25 15:49:28 +0800
committer魏曹先生 <1992414357@qq.com>2025-09-25 15:49:28 +0800
commit0eeb842c21ff1681e77ccbd47fe7a3c9779a65d5 (patch)
tree8c3ffb1f97dbbedb7756fb33f519547083047f24 /crates
parent2865206dda1d57df1c95dd8e49d5599db89407ae (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')
-rw-r--r--crates/utils/cfg_file/cfg_file_test/src/lib.rs2
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_challenge.rs160
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_connection.rs42
-rw-r--r--crates/utils/tcp_connection/tcp_connection_test/src/test_file_transfer.rs34
-rw-r--r--crates/vcs/vcs_test/src/test_vault_setup_and_member_register.rs12
-rw-r--r--crates/vcs/vcs_test/src/test_virtual_file_creation_and_update.rs154
6 files changed, 191 insertions, 213 deletions
diff --git a/crates/utils/cfg_file/cfg_file_test/src/lib.rs b/crates/utils/cfg_file/cfg_file_test/src/lib.rs
index 800dfe7..4db4c22 100644
--- a/crates/utils/cfg_file/cfg_file_test/src/lib.rs
+++ b/crates/utils/cfg_file/cfg_file_test/src/lib.rs
@@ -19,7 +19,7 @@ mod test_cfg_file {
let mut example = ExampleConfig {
name: "Weicao".to_string(),
age: 22,
- hobby: vec!["Programming", "Painting"]
+ hobby: ["Programming", "Painting"]
.iter()
.map(|m| m.to_string())
.collect(),
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_challenge.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_challenge.rs
index 0ca8540..95b0e3c 100644
--- a/crates/utils/tcp_connection/tcp_connection_test/src/test_challenge.rs
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_challenge.rs
@@ -14,94 +14,90 @@ use tokio::{
pub(crate) struct ExampleChallengeClientHandle;
impl ClientHandle<ExampleChallengeServerHandle> for ExampleChallengeClientHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- // Accept challenge with correct key
- let key = current_dir()
- .unwrap()
- .join("res")
- .join("key")
- .join("test_key_private.pem");
- let result = instance.accept_challenge(key, "test_key").await.unwrap();
-
- // Sent success
- assert_eq!(true, result);
- let response = instance.read_text().await.unwrap();
-
- // Verify success
- assert_eq!("OK", response);
-
- // Accept challenge with wrong key
- let key = current_dir()
- .unwrap()
- .join("res")
- .join("key")
- .join("wrong_key_private.pem");
- let result = instance.accept_challenge(key, "test_key").await.unwrap();
-
- // Sent success
- assert_eq!(true, result);
- let response = instance.read_text().await.unwrap();
-
- // Verify fail
- assert_eq!("ERROR", response);
-
- // Accept challenge with wrong name
- let key = current_dir()
- .unwrap()
- .join("res")
- .join("key")
- .join("test_key_private.pem");
- let result = instance.accept_challenge(key, "test_key__").await.unwrap();
-
- // Sent success
- assert_eq!(true, result);
- let response = instance.read_text().await.unwrap();
-
- // Verify fail
- assert_eq!("ERROR", response);
- }
+ async fn process(mut instance: ConnectionInstance) {
+ // Accept challenge with correct key
+ let key = current_dir()
+ .unwrap()
+ .join("res")
+ .join("key")
+ .join("test_key_private.pem");
+ let result = instance.accept_challenge(key, "test_key").await.unwrap();
+
+ // Sent success
+ assert!(result);
+ let response = instance.read_text().await.unwrap();
+
+ // Verify success
+ assert_eq!("OK", response);
+
+ // Accept challenge with wrong key
+ let key = current_dir()
+ .unwrap()
+ .join("res")
+ .join("key")
+ .join("wrong_key_private.pem");
+ let result = instance.accept_challenge(key, "test_key").await.unwrap();
+
+ // Sent success
+ assert!(result);
+ let response = instance.read_text().await.unwrap();
+
+ // Verify fail
+ assert_eq!("ERROR", response);
+
+ // Accept challenge with wrong name
+ let key = current_dir()
+ .unwrap()
+ .join("res")
+ .join("key")
+ .join("test_key_private.pem");
+ let result = instance.accept_challenge(key, "test_key__").await.unwrap();
+
+ // Sent success
+ assert!(result);
+ let response = instance.read_text().await.unwrap();
+
+ // Verify fail
+ assert_eq!("ERROR", response);
}
}
pub(crate) struct ExampleChallengeServerHandle;
impl ServerHandle<ExampleChallengeClientHandle> for ExampleChallengeServerHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- // Challenge with correct key
- let key_dir = current_dir().unwrap().join("res").join("key");
- let result = instance.challenge(key_dir).await.unwrap();
- assert_eq!(true, result);
-
- // Send response
- instance
- .write_text(if result { "OK" } else { "ERROR" })
- .await
- .unwrap();
-
- // Challenge again
- let key_dir = current_dir().unwrap().join("res").join("key");
- let result = instance.challenge(key_dir).await.unwrap();
- assert_eq!(false, result);
-
- // Send response
- instance
- .write_text(if result { "OK" } else { "ERROR" })
- .await
- .unwrap();
-
- // Challenge again
- let key_dir = current_dir().unwrap().join("res").join("key");
- let result = instance.challenge(key_dir).await.unwrap();
- assert_eq!(false, result);
-
- // Send response
- instance
- .write_text(if result { "OK" } else { "ERROR" })
- .await
- .unwrap();
- }
+ async fn process(mut instance: ConnectionInstance) {
+ // Challenge with correct key
+ let key_dir = current_dir().unwrap().join("res").join("key");
+ let result = instance.challenge(key_dir).await.unwrap();
+ assert!(result);
+
+ // Send response
+ instance
+ .write_text(if result { "OK" } else { "ERROR" })
+ .await
+ .unwrap();
+
+ // Challenge again
+ let key_dir = current_dir().unwrap().join("res").join("key");
+ let result = instance.challenge(key_dir).await.unwrap();
+ assert!(!result);
+
+ // Send response
+ instance
+ .write_text(if result { "OK" } else { "ERROR" })
+ .await
+ .unwrap();
+
+ // Challenge again
+ let key_dir = current_dir().unwrap().join("res").join("key");
+ let result = instance.challenge(key_dir).await.unwrap();
+ assert!(!result);
+
+ // Send response
+ instance
+ .write_text(if result { "OK" } else { "ERROR" })
+ .await
+ .unwrap();
}
}
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_connection.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_connection.rs
index 6238c39..79aac65 100644
--- a/crates/utils/tcp_connection/tcp_connection_test/src/test_connection.rs
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_connection.rs
@@ -11,35 +11,31 @@ use tokio::{join, time::sleep};
pub(crate) struct ExampleClientHandle;
impl ClientHandle<ExampleServerHandle> for ExampleClientHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- // Write name
- let Ok(_) = instance.write_text("Peter").await else {
- panic!("Write text failed!");
- };
- // Read msg
- let Ok(result) = instance.read_text().await else {
- return;
- };
- assert_eq!("Hello Peter!", result);
- }
+ async fn process(mut instance: ConnectionInstance) {
+ // Write name
+ let Ok(_) = instance.write_text("Peter").await else {
+ panic!("Write text failed!");
+ };
+ // Read msg
+ let Ok(result) = instance.read_text().await else {
+ return;
+ };
+ assert_eq!("Hello Peter!", result);
}
}
pub(crate) struct ExampleServerHandle;
impl ServerHandle<ExampleClientHandle> for ExampleServerHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- // Read name
- let Ok(name) = instance.read_text().await else {
- return;
- };
- // Write msg
- let Ok(_) = instance.write_text(format!("Hello {}!", name)).await else {
- panic!("Write text failed!");
- };
- }
+ async fn process(mut instance: ConnectionInstance) {
+ // Read name
+ let Ok(name) = instance.read_text().await else {
+ return;
+ };
+ // Write msg
+ let Ok(_) = instance.write_text(format!("Hello {}!", name)).await else {
+ panic!("Write text failed!");
+ };
}
}
diff --git a/crates/utils/tcp_connection/tcp_connection_test/src/test_file_transfer.rs b/crates/utils/tcp_connection/tcp_connection_test/src/test_file_transfer.rs
index d316080..9425d30 100644
--- a/crates/utils/tcp_connection/tcp_connection_test/src/test_file_transfer.rs
+++ b/crates/utils/tcp_connection/tcp_connection_test/src/test_file_transfer.rs
@@ -14,31 +14,27 @@ use tokio::{
pub(crate) struct ExampleFileTransferClientHandle;
impl ClientHandle<ExampleFileTransferServerHandle> for ExampleFileTransferClientHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- let image_path = current_dir()
- .unwrap()
- .join("res")
- .join("image")
- .join("test_transfer.png");
- instance.write_file(image_path).await.unwrap();
- }
+ async fn process(mut instance: ConnectionInstance) {
+ let image_path = current_dir()
+ .unwrap()
+ .join("res")
+ .join("image")
+ .join("test_transfer.png");
+ instance.write_file(image_path).await.unwrap();
}
}
pub(crate) struct ExampleFileTransferServerHandle;
impl ServerHandle<ExampleFileTransferClientHandle> for ExampleFileTransferServerHandle {
- fn process(mut instance: ConnectionInstance) -> impl std::future::Future<Output = ()> + Send {
- async move {
- let save_path = current_dir()
- .unwrap()
- .join("res")
- .join(".temp")
- .join("image")
- .join("test_transfer.png");
- instance.read_file(save_path).await.unwrap();
- }
+ async fn process(mut instance: ConnectionInstance) {
+ let save_path = current_dir()
+ .unwrap()
+ .join("res")
+ .join(".temp")
+ .join("image")
+ .join("test_transfer.png");
+ instance.read_file(save_path).await.unwrap();
}
}
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();
}
}