From 663f23ccbfbc9b27db21c16426fa2dc76cdd674f Mon Sep 17 00:00:00 2001 From: Mahdi Robatipoor Date: Tue, 20 Feb 2024 12:56:41 +0330 Subject: [PATCH] update strum and resolve clippy warning message --- Cargo.toml | 6 +++--- src/entity/role.rs | 2 +- src/repo/message.rs | 2 +- src/util/assertion.rs | 2 +- tests/api/admin_endpoint_tests/test_user_list.rs | 2 +- tests/api/helper/assert.rs | 9 +++++++-- tests/api/helper/email.rs | 6 +++--- tests/api/helper/user.rs | 3 +-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d58876..a1911bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,12 @@ path = "./src/bin/migration.rs" [dependencies] axum = { version = "0.7.4", features = ["ws"] } axum-extra = { version = "0.9.2", features = ["typed-header"] } -sea-orm = { version = "0.12.11", features = [ +sea-orm = { version = "0.12.14", features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", ] } -sea-orm-migration = { version = "0.12.11", features = [ +sea-orm-migration = { version = "0.12.14", features = [ "runtime-tokio-rustls", "sqlx-postgres", ] } @@ -56,7 +56,7 @@ sentry = "0.32.2" serde = { version = "1.0.196", features = ["derive"] } serde_json = "1.0.113" sha2 = "0.10.8" -strum = { version = "0.25.0", features = ["derive"] } +strum = { version = "0.26.1", features = ["derive"] } tera = "1.19.1" test-context = "0.1.4" thiserror = "1.0.57" diff --git a/src/entity/role.rs b/src/entity/role.rs index f4a6f33..d658148 100644 --- a/src/entity/role.rs +++ b/src/entity/role.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; fake::Dummy, Clone, Copy, - strum::EnumIter, + EnumIter, strum::Display, Hash, DeriveActiveEnum, diff --git a/src/repo/message.rs b/src/repo/message.rs index 756f02f..8a3a4b0 100644 --- a/src/repo/message.rs +++ b/src/repo/message.rs @@ -185,7 +185,7 @@ mod tests { assert_eq!(list.len(), 2); let list = get_list_and_update(&**ctx, 100, 2).await.unwrap(); assert_eq!(list.len(), 1); - assert_eq!(list.get(0).unwrap().content, "code3"); + assert_eq!(list.first().unwrap().content, "code3"); let list = get_list_and_update(&**ctx, 100, 2).await.unwrap(); assert_eq!(list.len(), 0); } diff --git a/src/util/assertion.rs b/src/util/assertion.rs index 6d86c3a..54906e9 100644 --- a/src/util/assertion.rs +++ b/src/util/assertion.rs @@ -21,7 +21,7 @@ where count(result) == count(expected) } -pub fn vecs_match(a: &Vec, b: &Vec) -> bool { +pub fn vecs_match(a: &[T], b: &[T]) -> bool { a.len() == b.len() && !a.iter().zip(b.iter()).any(|(a, b)| *a != *b) } diff --git a/tests/api/admin_endpoint_tests/test_user_list.rs b/tests/api/admin_endpoint_tests/test_user_list.rs index 705a1fa..69e4ceb 100644 --- a/tests/api/admin_endpoint_tests/test_user_list.rs +++ b/tests/api/admin_endpoint_tests/test_user_list.rs @@ -26,6 +26,6 @@ pub async fn test_success_get_user_list(ctx: &mut SeedDbTestContext) { .await .unwrap(); let resp = unwrap!(resp); - assert!(resp.list.len() > 0); + assert!(!resp.list.is_empty()); assert!(status.is_success(), "status: {status}"); } diff --git a/tests/api/helper/assert.rs b/tests/api/helper/assert.rs index 7984c96..b0d9afa 100644 --- a/tests/api/helper/assert.rs +++ b/tests/api/helper/assert.rs @@ -1,19 +1,24 @@ #[macro_export] macro_rules! assert_err { ($result:expr $(, $closure:expr )?) => { + #[allow(clippy::redundant_closure_call)] + { assert!( matches!($result, $crate::helper::result::AppResponseResult::Err(ref _e) $( if $closure(_e) )?), "Match failed: {:?}",$result, ) - }; + }}; } #[macro_export] macro_rules! assert_ok { + ($result:expr $(, $closure:expr )?) => { + #[allow(clippy::redundant_closure_call)] + { assert!( matches!($result, $crate::helper::result::AppResponseResult::Ok(ref _d) $( if $closure(_d) )?), "Match failed: {:?}",$result, ) - }; + }}; } diff --git a/tests/api/helper/email.rs b/tests/api/helper/email.rs index 08a6691..8e83b7d 100644 --- a/tests/api/helper/email.rs +++ b/tests/api/helper/email.rs @@ -83,7 +83,7 @@ impl MailHogClient { }; let resp = rustfulapi::retry!(resp, |r: &Result| { match r { - Ok(r) => r.items.len() >= 1, + Ok(r) => !r.items.is_empty(), Err(_) => false, } }); @@ -95,7 +95,7 @@ impl MailHogClient { let resp = self.search(QueryKindSearch::To, email).await?; let body = resp .items - .get(0) + .first() .ok_or_else(|| anyhow!("Item not found"))? .content .body @@ -117,7 +117,7 @@ impl MailHogClient { .ok_or_else(|| anyhow!("Item not found"))? .text() .collect::(); - let _ = self.delete(resp.items.get(0).unwrap().id.clone()).await; + let _ = self.delete(resp.items.first().unwrap().id.clone()).await; Ok((code, user_id)) } } diff --git a/tests/api/helper/user.rs b/tests/api/helper/user.rs index a9700aa..12a72bc 100644 --- a/tests/api/helper/user.rs +++ b/tests/api/helper/user.rs @@ -5,8 +5,7 @@ use fake::faker::internet::en::FreeEmail; use fake::{Fake, Faker}; use rustfulapi::{entity, util}; use rustfulapi::{entity::role::RoleUser, error::AppResult}; -use sea_orm::{ActiveModelTrait, DatabaseConnection, Set}; -use strum::IntoEnumIterator; +use sea_orm::{ActiveModelTrait, DatabaseConnection, Iterable, Set}; use uuid::Uuid; pub struct TestUser {