From 7281340423aec9b2b2568a6d78eaf2e061be04b5 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Fri, 28 Apr 2023 00:01:24 +0200 Subject: [PATCH] Apply clippy suggestions --- fedimovies-cli/src/main.rs | 7 +-- fedimovies-models/src/attachments/queries.rs | 2 +- fedimovies-models/src/posts/helpers.rs | 40 ++++++-------- fedimovies-models/src/posts/queries.rs | 54 +++++++++---------- fedimovies-models/src/profiles/queries.rs | 6 +-- .../src/relationships/queries.rs | 2 +- .../src/subscriptions/queries.rs | 2 +- fedimovies-models/src/users/queries.rs | 2 +- fedimovies-utils/src/crypto_rsa.rs | 6 +-- fedimovies-utils/src/passwords.rs | 2 +- fedimovies-utils/src/urls.rs | 2 +- src/activitypub/actors/attachments.rs | 2 +- src/activitypub/builders/accept_follow.rs | 2 +- src/activitypub/builders/announce.rs | 2 +- src/activitypub/builders/create_note.rs | 8 +-- src/activitypub/builders/like.rs | 2 +- src/activitypub/views.rs | 6 +-- src/http_signatures/create.rs | 12 ++--- src/http_signatures/verify.rs | 4 +- src/ipfs/posts.rs | 2 +- src/job_queue/periodic_tasks.rs | 6 +-- src/json_signatures/verify.rs | 2 +- src/main.rs | 2 +- src/mastodon_api/accounts/helpers.rs | 52 +++++++++--------- .../statuses/microsyntax/links.rs | 2 +- src/validators/posts.rs | 2 +- src/validators/profiles.rs | 2 +- src/validators/users.rs | 4 +- 28 files changed, 111 insertions(+), 126 deletions(-) diff --git a/fedimovies-cli/src/main.rs b/fedimovies-cli/src/main.rs index 3ad2d11..ece64da 100644 --- a/fedimovies-cli/src/main.rs +++ b/fedimovies-cli/src/main.rs @@ -25,11 +25,8 @@ async fn main() { } let db_config = config.database_url.parse().unwrap(); - let db_client = &mut create_database_client( - &db_config, - config.tls_ca_file.as_ref().map(|p| p.as_path()), - ) - .await; + let db_client = + &mut create_database_client(&db_config, config.tls_ca_file.as_deref()).await; apply_migrations(db_client).await; match subcmd { diff --git a/fedimovies-models/src/attachments/queries.rs b/fedimovies-models/src/attachments/queries.rs index 8fb9b90..bca24e1 100644 --- a/fedimovies-models/src/attachments/queries.rs +++ b/fedimovies-models/src/attachments/queries.rs @@ -127,6 +127,6 @@ mod tests { assert_eq!(attachment.file_name, file_name); assert_eq!(attachment.file_size.unwrap(), file_size as i32); assert_eq!(attachment.media_type.unwrap(), media_type); - assert_eq!(attachment.post_id.is_none(), true); + assert!(attachment.post_id.is_none()); } } diff --git a/fedimovies-models/src/posts/helpers.rs b/fedimovies-models/src/posts/helpers.rs index ba8f0c1..f6d6361 100644 --- a/fedimovies-models/src/posts/helpers.rs +++ b/fedimovies-models/src/posts/helpers.rs @@ -172,7 +172,7 @@ mod tests { let post = create_post(db_client, &author.id, post_data).await.unwrap(); let reply_data = PostCreateData { content: "reply".to_string(), - in_reply_to_id: Some(post.id.clone()), + in_reply_to_id: Some(post.id), ..Default::default() }; let mut reply = create_post(db_client, &author.id, reply_data) @@ -182,8 +182,8 @@ mod tests { .await .unwrap(); assert_eq!(reply.in_reply_to.unwrap().id, post.id); - assert_eq!(reply.repost_of.is_none(), true); - assert_eq!(reply.linked.is_empty(), true); + assert!(reply.repost_of.is_none()); + assert!(reply.linked.is_empty()); } #[tokio::test] @@ -195,7 +195,7 @@ mod tests { }; let db_client = &create_test_database().await; let result = can_view_post(db_client, None, &post).await.unwrap(); - assert_eq!(result, true); + assert!(result); } #[tokio::test] @@ -208,7 +208,7 @@ mod tests { }; let db_client = &create_test_database().await; let result = can_view_post(db_client, Some(&user), &post).await.unwrap(); - assert_eq!(result, false); + assert!(!result); } #[tokio::test] @@ -222,7 +222,7 @@ mod tests { }; let db_client = &create_test_database().await; let result = can_view_post(db_client, Some(&user), &post).await.unwrap(); - assert_eq!(result, true); + assert!(result); } #[tokio::test] @@ -236,7 +236,7 @@ mod tests { ..Default::default() }; let result = can_view_post(db_client, None, &post).await.unwrap(); - assert_eq!(result, false); + assert!(!result); } #[tokio::test] @@ -254,7 +254,7 @@ mod tests { let result = can_view_post(db_client, Some(&follower), &post) .await .unwrap(); - assert_eq!(result, true); + assert!(result); } #[tokio::test] @@ -274,19 +274,13 @@ mod tests { mentions: vec![subscriber.profile.clone()], ..Default::default() }; - assert_eq!(can_view_post(db_client, None, &post).await.unwrap(), false,); - assert_eq!( - can_view_post(db_client, Some(&follower), &post) - .await - .unwrap(), - false, - ); - assert_eq!( - can_view_post(db_client, Some(&subscriber), &post) - .await - .unwrap(), - true, - ); + assert!(!can_view_post(db_client, None, &post).await.unwrap(),); + assert!(!can_view_post(db_client, Some(&follower), &post) + .await + .unwrap(),); + assert!(can_view_post(db_client, Some(&subscriber), &post) + .await + .unwrap(),); } #[test] @@ -295,8 +289,8 @@ mod tests { role: Role::NormalUser, ..Default::default() }; - assert_eq!(can_create_post(&user), true); + assert!(can_create_post(&user)); user.role = Role::ReadOnlyUser; - assert_eq!(can_create_post(&user), false); + assert!(!can_create_post(&user)); } } diff --git a/fedimovies-models/src/posts/queries.rs b/fedimovies-models/src/posts/queries.rs index 302c856..12c86c9 100644 --- a/fedimovies-models/src/posts/queries.rs +++ b/fedimovies-models/src/posts/queries.rs @@ -1348,10 +1348,10 @@ mod tests { let post = create_post(db_client, &author.id, post_data).await.unwrap(); assert_eq!(post.content, "test post"); assert_eq!(post.author.id, author.id); - assert_eq!(post.attachments.is_empty(), true); - assert_eq!(post.mentions.is_empty(), true); - assert_eq!(post.tags.is_empty(), true); - assert_eq!(post.links.is_empty(), true); + assert!(post.attachments.is_empty()); + assert!(post.mentions.is_empty()); + assert!(post.tags.is_empty()); + assert!(post.links.is_empty()); assert_eq!(post.updated_at, None); } @@ -1401,7 +1401,7 @@ mod tests { update_post(db_client, &post.id, post_data).await.unwrap(); let post = get_post_by_id(db_client, &post.id).await.unwrap(); assert_eq!(post.content, "test update"); - assert_eq!(post.updated_at.is_some(), true); + assert!(post.updated_at.is_some()); } #[tokio::test] @@ -1590,19 +1590,19 @@ mod tests { .await .unwrap(); assert_eq!(timeline.len(), 7); - assert_eq!(timeline.iter().any(|post| post.id == post_1.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_2.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_3.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_4.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_5.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_6.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_7.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_8.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_9.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_10.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_11.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_12.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_13.id), false); + assert!(timeline.iter().any(|post| post.id == post_1.id)); + assert!(timeline.iter().any(|post| post.id == post_2.id)); + assert!(!timeline.iter().any(|post| post.id == post_3.id)); + assert!(timeline.iter().any(|post| post.id == post_4.id)); + assert!(!timeline.iter().any(|post| post.id == post_5.id)); + assert!(timeline.iter().any(|post| post.id == post_6.id)); + assert!(timeline.iter().any(|post| post.id == post_7.id)); + assert!(!timeline.iter().any(|post| post.id == post_8.id)); + assert!(timeline.iter().any(|post| post.id == post_9.id)); + assert!(!timeline.iter().any(|post| post.id == post_10.id)); + assert!(!timeline.iter().any(|post| post.id == post_11.id)); + assert!(timeline.iter().any(|post| post.id == post_12.id)); + assert!(!timeline.iter().any(|post| post.id == post_13.id)); } #[tokio::test] @@ -1645,13 +1645,13 @@ mod tests { // Reply let reply_data = PostCreateData { content: "my reply".to_string(), - in_reply_to_id: Some(post_1.id.clone()), + in_reply_to_id: Some(post_1.id), ..Default::default() }; let reply = create_post(db_client, &user.id, reply_data).await.unwrap(); // Repost let repost_data = PostCreateData { - repost_of_id: Some(reply.id.clone()), + repost_of_id: Some(reply.id), ..Default::default() }; let repost = create_post(db_client, &user.id, repost_data).await.unwrap(); @@ -1661,12 +1661,12 @@ mod tests { .await .unwrap(); assert_eq!(timeline.len(), 2); - assert_eq!(timeline.iter().any(|post| post.id == post_1.id), true); - assert_eq!(timeline.iter().any(|post| post.id == post_2.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_3.id), false); - assert_eq!(timeline.iter().any(|post| post.id == post_4.id), false); - assert_eq!(timeline.iter().any(|post| post.id == reply.id), false); - assert_eq!(timeline.iter().any(|post| post.id == repost.id), true); + assert!(timeline.iter().any(|post| post.id == post_1.id)); + assert!(!timeline.iter().any(|post| post.id == post_2.id)); + assert!(!timeline.iter().any(|post| post.id == post_3.id)); + assert!(!timeline.iter().any(|post| post.id == post_4.id)); + assert!(!timeline.iter().any(|post| post.id == reply.id)); + assert!(timeline.iter().any(|post| post.id == repost.id)); } #[tokio::test] @@ -1686,7 +1686,7 @@ mod tests { let post_1 = create_post(db_client, &user.id, post_data_1).await.unwrap(); let post_data_2 = PostCreateData { content: "my reply".to_string(), - in_reply_to_id: Some(post_1.id.clone()), + in_reply_to_id: Some(post_1.id), ..Default::default() }; let post_2 = create_post(db_client, &user.id, post_data_2).await.unwrap(); diff --git a/fedimovies-models/src/profiles/queries.rs b/fedimovies-models/src/profiles/queries.rs index fed08ed..7686b99 100644 --- a/fedimovies-models/src/profiles/queries.rs +++ b/fedimovies-models/src/profiles/queries.rs @@ -932,7 +932,7 @@ mod tests { .unwrap(); let profile_data = ProfileCreateData { username: "test".to_string(), - emojis: vec![emoji.id.clone()], + emojis: vec![emoji.id], ..Default::default() }; let profile = create_profile(db_client, profile_data).await.unwrap(); @@ -1078,7 +1078,7 @@ mod tests { .await .unwrap(); let profile = get_profile_by_id(db_client, &profile.id).await.unwrap(); - assert_eq!(profile.unreachable_since.is_some(), true); + assert!(profile.unreachable_since.is_some()); } #[tokio::test] @@ -1089,6 +1089,6 @@ mod tests { let profiles = find_empty_profiles(db_client, &updated_before) .await .unwrap(); - assert_eq!(profiles.is_empty(), true); + assert!(profiles.is_empty()); } } diff --git a/fedimovies-models/src/relationships/queries.rs b/fedimovies-models/src/relationships/queries.rs index f8f138e..fba2a67 100644 --- a/fedimovies-models/src/relationships/queries.rs +++ b/fedimovies-models/src/relationships/queries.rs @@ -727,7 +727,7 @@ mod tests { let target_has_followers = has_local_followers(db_client, target_actor_id) .await .unwrap(); - assert_eq!(target_has_followers, true); + assert!(target_has_followers); // Unfollow let follow_request_id = unfollow(db_client, &source.id, &target.id) diff --git a/fedimovies-models/src/subscriptions/queries.rs b/fedimovies-models/src/subscriptions/queries.rs index f74c6eb..bfdf7ab 100644 --- a/fedimovies-models/src/subscriptions/queries.rs +++ b/fedimovies-models/src/subscriptions/queries.rs @@ -249,6 +249,6 @@ mod tests { ) .await .unwrap(); - assert_eq!(is_subscribed, true); + assert!(is_subscribed); } } diff --git a/fedimovies-models/src/users/queries.rs b/fedimovies-models/src/users/queries.rs index 6985c50..9c7c13e 100644 --- a/fedimovies-models/src/users/queries.rs +++ b/fedimovies-models/src/users/queries.rs @@ -420,7 +420,7 @@ mod tests { ..Default::default() }; let user = create_user(db_client, user_data).await.unwrap(); - assert_eq!(user.client_config.is_empty(), true); + assert!(user.client_config.is_empty()); let client_name = "test"; let client_config_value = json!({"a": 1}); let client_config = diff --git a/fedimovies-utils/src/crypto_rsa.rs b/fedimovies-utils/src/crypto_rsa.rs index debf268..8882656 100644 --- a/fedimovies-utils/src/crypto_rsa.rs +++ b/fedimovies-utils/src/crypto_rsa.rs @@ -85,8 +85,8 @@ mod tests { fn test_deserialize_public_key_nowrap() { let public_key_pem = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8ehqQ7n6+pw19U8q2UtxE/9017STW3yRnnqV5nVk8LJ00ba+berqwekxDW+nw77GAu3TJ+hYeeSerUNPup7y3yO3V YsFtrgWDQ/s8k86sNBU+Ce2GOL7seh46kyAWgJeohh4Rcrr23rftHbvxOcRM8VzYuCeb1DgVhPGtA0xULwIDAQAB\n-----END PUBLIC KEY-----"; - let result = deserialize_public_key(&public_key_pem); - assert_eq!(result.is_ok(), true); + let result = deserialize_public_key(public_key_pem); + assert!(result.is_ok()); } #[test] @@ -105,6 +105,6 @@ YsFtrgWDQ/s8k86sNBU+Ce2GOL7seh46kyAWgJeohh4Rcrr23rftHbvxOcRM8VzYuCeb1DgVhPGtA0xU let public_key = RsaPublicKey::from(&private_key); let is_valid = verify_rsa_sha256_signature(&public_key, &message, &signature); - assert_eq!(is_valid, true); + assert!(is_valid); } } diff --git a/fedimovies-utils/src/passwords.rs b/fedimovies-utils/src/passwords.rs index 0013ed0..22d42f0 100644 --- a/fedimovies-utils/src/passwords.rs +++ b/fedimovies-utils/src/passwords.rs @@ -20,6 +20,6 @@ mod tests { let password = "$test123"; let password_hash = hash_password(password).unwrap(); let result = verify_password(&password_hash, password); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); } } diff --git a/fedimovies-utils/src/urls.rs b/fedimovies-utils/src/urls.rs index dabba66..f58591a 100644 --- a/fedimovies-utils/src/urls.rs +++ b/fedimovies-utils/src/urls.rs @@ -89,7 +89,7 @@ mod tests { fn test_get_hostname_email() { let url = "mailto:user@example.org"; let result = get_hostname(url); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); } #[test] diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index e7c46e3..944c179 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -28,7 +28,7 @@ pub fn parse_identity_proof( _actor_id: &str, _attachment: &ActorAttachment, ) -> Result { - return Err(ValidationError("incorrect proof type".to_string())); + Err(ValidationError("incorrect proof type".to_string())) } pub fn attach_payment_option( diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index ec31281..38b4669 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -80,7 +80,7 @@ mod tests { let follower_id = "https://test.remote/users/123"; let activity = build_accept_follow(INSTANCE_URL, &target, follower_id, follow_activity_id); - assert_eq!(activity.id.starts_with(INSTANCE_URL), true); + assert!(activity.id.starts_with(INSTANCE_URL)); assert_eq!(activity.activity_type, "Accept"); assert_eq!(activity.object, follow_activity_id); assert_eq!(activity.to, vec![follower_id]); diff --git a/src/activitypub/builders/announce.rs b/src/activitypub/builders/announce.rs index 5808784..2d16894 100644 --- a/src/activitypub/builders/announce.rs +++ b/src/activitypub/builders/announce.rs @@ -117,7 +117,7 @@ mod tests { }; let post_id = "https://test.net/obj/123"; let post = Post { - author: post_author.clone(), + author: post_author, object_id: Some(post_id.to_string()), ..Default::default() }; diff --git a/src/activitypub/builders/create_note.rs b/src/activitypub/builders/create_note.rs index 4dc98b6..4dfcc51 100644 --- a/src/activitypub/builders/create_note.rs +++ b/src/activitypub/builders/create_note.rs @@ -339,7 +339,7 @@ mod tests { note.attributed_to, format!("{}/users/{}", INSTANCE_URL, post.author.username), ); - assert_eq!(note.in_reply_to.is_none(), true); + assert!(note.in_reply_to.is_none()); assert_eq!(note.content, post.content); assert_eq!(note.to, vec![AP_PUBLIC]); assert_eq!( @@ -367,7 +367,7 @@ mod tests { note.to, vec![local_actor_followers(INSTANCE_URL, &post.author.username),] ); - assert_eq!(note.cc.is_empty(), true); + assert!(note.cc.is_empty()); } #[test] @@ -397,7 +397,7 @@ mod tests { subscriber_id.to_string(), ] ); - assert_eq!(note.cc.is_empty(), true); + assert!(note.cc.is_empty()); } #[test] @@ -421,7 +421,7 @@ mod tests { let note = build_note(INSTANCE_HOSTNAME, INSTANCE_URL, &post); assert_eq!(note.to, vec![mentioned_id]); - assert_eq!(note.cc.is_empty(), true); + assert!(note.cc.is_empty()); } #[test] diff --git a/src/activitypub/builders/like.rs b/src/activitypub/builders/like.rs index 06f929e..e912611 100644 --- a/src/activitypub/builders/like.rs +++ b/src/activitypub/builders/like.rs @@ -129,6 +129,6 @@ mod tests { ); assert_eq!(activity.object, post_id); assert_eq!(activity.to, vec![post_author_id, AP_PUBLIC]); - assert_eq!(activity.cc.is_empty(), true); + assert!(activity.cc.is_empty()); } } diff --git a/src/activitypub/views.rs b/src/activitypub/views.rs index 701fb54..f085413 100644 --- a/src/activitypub/views.rs +++ b/src/activitypub/views.rs @@ -357,7 +357,7 @@ mod tests { HeaderValue::from_static(r#"application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", text/html;q=0.1"#), ); let result = is_activitypub_request(&request_headers); - assert_eq!(result, true); + assert!(result); } #[test] @@ -368,7 +368,7 @@ mod tests { HeaderValue::from_static("application/activity+json"), ); let result = is_activitypub_request(&request_headers); - assert_eq!(result, true); + assert!(result); } #[test] @@ -376,6 +376,6 @@ mod tests { let mut request_headers = HeaderMap::new(); request_headers.insert(header::ACCEPT, HeaderValue::from_static("text/html")); let result = is_activitypub_request(&request_headers); - assert_eq!(result, false); + assert!(!result); } } diff --git a/src/http_signatures/create.rs b/src/http_signatures/create.rs index f42204f..cbd90b1 100644 --- a/src/http_signatures/create.rs +++ b/src/http_signatures/create.rs @@ -107,10 +107,7 @@ mod tests { r#"headers="(request-target) host date","#, r#"signature=""#, ); - assert_eq!( - headers.signature.starts_with(expected_signature_header), - true, - ); + assert!(headers.signature.starts_with(expected_signature_header),); } #[test] @@ -127,7 +124,7 @@ mod tests { &signer_key, signer_key_id, ); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); let headers = result.unwrap(); assert_eq!(headers.host, "example.org"); @@ -141,9 +138,6 @@ mod tests { r#"headers="(request-target) host date digest","#, r#"signature=""#, ); - assert_eq!( - headers.signature.starts_with(expected_signature_header), - true, - ); + assert!(headers.signature.starts_with(expected_signature_header),); } } diff --git a/src/http_signatures/verify.rs b/src/http_signatures/verify.rs index afe5305..3c6c46b 100644 --- a/src/http_signatures/verify.rs +++ b/src/http_signatures/verify.rs @@ -183,7 +183,7 @@ mod tests { request_headers.insert(header::HOST, HeaderValue::from_static("example.com")); request_headers.insert( HeaderName::from_static("date"), - HeaderValue::from_str(&date).unwrap(), + HeaderValue::from_str(date).unwrap(), ); let signature_header = concat!( r#"keyId="https://myserver.org/actor#main-key","#, @@ -245,6 +245,6 @@ mod tests { let signer_public_key = RsaPublicKey::from(signer_key); let result = verify_http_signature(&signature_data, &signer_public_key); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); } } diff --git a/src/ipfs/posts.rs b/src/ipfs/posts.rs index e8b4d98..a006921 100644 --- a/src/ipfs/posts.rs +++ b/src/ipfs/posts.rs @@ -80,6 +80,6 @@ mod tests { assert_eq!(post_metadata.external_url, post_url); let created_at_attr = &post_metadata.attributes[0]; assert_eq!(created_at_attr.display_type, "date"); - assert_eq!(created_at_attr.value.as_i64().is_some(), true); + assert!(created_at_attr.value.as_i64().is_some()); } } diff --git a/src/job_queue/periodic_tasks.rs b/src/job_queue/periodic_tasks.rs index 2ea3367..3f4924e 100644 --- a/src/job_queue/periodic_tasks.rs +++ b/src/job_queue/periodic_tasks.rs @@ -120,7 +120,7 @@ pub async fn handle_movies_mentions( current_user.profile.username, post_id ); - delete_notification(&mut transaction, mention_notification.id).await?; + delete_notification(&transaction, mention_notification.id).await?; continue; } Err(err) => return Err(err.into()), @@ -131,11 +131,11 @@ pub async fn handle_movies_mentions( // Federate prepare_announce(&transaction, &config.instance(), ¤t_user, &repost) .await? - .enqueue(&mut transaction) + .enqueue(&transaction) .await?; // Delete notification to avoid re-processing - delete_notification(&mut transaction, mention_notification.id).await?; + delete_notification(&transaction, mention_notification.id).await?; log::info!( "Review as Mention of {} reposted with post id {}", diff --git a/src/json_signatures/verify.rs b/src/json_signatures/verify.rs index 9e4d570..9df079b 100644 --- a/src/json_signatures/verify.rs +++ b/src/json_signatures/verify.rs @@ -171,6 +171,6 @@ mod tests { let signer_public_key = RsaPublicKey::from(signer_key); let result = verify_rsa_json_signature(&signature_data, &signer_public_key); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); } } diff --git a/src/main.rs b/src/main.rs index 689374e..e5612a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ async fn main() -> std::io::Result<()> { let db_pool_size = num_cpus::get() * 2; let db_pool = create_pool( &config.database_url, - config.tls_ca_file.as_ref().map(|s| s.as_path()), + config.tls_ca_file.as_deref(), db_pool_size, ); let mut db_client = get_database_client(&db_pool).await.unwrap(); diff --git a/src/mastodon_api/accounts/helpers.rs b/src/mastodon_api/accounts/helpers.rs index 412137f..e3683a7 100644 --- a/src/mastodon_api/accounts/helpers.rs +++ b/src/mastodon_api/accounts/helpers.rs @@ -124,13 +124,13 @@ mod tests { .await .unwrap(); assert_eq!(relationship.id, user_2.id); - assert_eq!(relationship.following, false); - assert_eq!(relationship.followed_by, false); - assert_eq!(relationship.requested, false); - assert_eq!(relationship.subscription_to, false); - assert_eq!(relationship.subscription_from, false); - assert_eq!(relationship.showing_reblogs, true); - assert_eq!(relationship.showing_replies, true); + assert!(!relationship.following); + assert!(!relationship.followed_by); + assert!(!relationship.requested); + assert!(!relationship.subscription_to); + assert!(!relationship.subscription_from); + assert!(relationship.showing_reblogs); + assert!(relationship.showing_replies); // Follow request let follow_request = create_follow_request(db_client, &user_1.id, &user_2.id) .await @@ -138,9 +138,9 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, false); - assert_eq!(relationship.followed_by, false); - assert_eq!(relationship.requested, true); + assert!(!relationship.following); + assert!(!relationship.followed_by); + assert!(relationship.requested); // Mutual follow follow_request_accepted(db_client, &follow_request.id) .await @@ -149,17 +149,17 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, true); - assert_eq!(relationship.followed_by, true); - assert_eq!(relationship.requested, false); + assert!(relationship.following); + assert!(relationship.followed_by); + assert!(!relationship.requested); // Unfollow unfollow(db_client, &user_1.id, &user_2.id).await.unwrap(); let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, false); - assert_eq!(relationship.followed_by, true); - assert_eq!(relationship.requested, false); + assert!(!relationship.following); + assert!(relationship.followed_by); + assert!(!relationship.requested); } #[tokio::test] @@ -172,8 +172,8 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.subscription_to, true); - assert_eq!(relationship.subscription_from, false); + assert!(relationship.subscription_to); + assert!(!relationship.subscription_from); unsubscribe(db_client, &user_1.id, &user_2.id) .await @@ -181,8 +181,8 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.subscription_to, false); - assert_eq!(relationship.subscription_from, false); + assert!(!relationship.subscription_to); + assert!(!relationship.subscription_from); } #[tokio::test] @@ -194,8 +194,8 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, true); - assert_eq!(relationship.showing_reblogs, true); + assert!(relationship.following); + assert!(relationship.showing_reblogs); hide_reposts(db_client, &user_1.id, &user_2.id) .await @@ -203,8 +203,8 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, true); - assert_eq!(relationship.showing_reblogs, false); + assert!(relationship.following); + assert!(!relationship.showing_reblogs); show_reposts(db_client, &user_1.id, &user_2.id) .await @@ -212,7 +212,7 @@ mod tests { let relationship = get_relationship(db_client, &user_1.id, &user_2.id) .await .unwrap(); - assert_eq!(relationship.following, true); - assert_eq!(relationship.showing_reblogs, true); + assert!(relationship.following); + assert!(relationship.showing_reblogs); } } diff --git a/src/mastodon_api/statuses/microsyntax/links.rs b/src/mastodon_api/statuses/microsyntax/links.rs index b849733..61ede13 100644 --- a/src/mastodon_api/statuses/microsyntax/links.rs +++ b/src/mastodon_api/statuses/microsyntax/links.rs @@ -115,7 +115,7 @@ mod tests { let mat = regexp.find(text).unwrap(); assert_eq!(mat.start(), 9); let result = is_inside_code_block(&mat, text); - assert_eq!(result, true); + assert!(result); } #[test] diff --git a/src/validators/posts.rs b/src/validators/posts.rs index 5d4f7e8..104ff01 100644 --- a/src/validators/posts.rs +++ b/src/validators/posts.rs @@ -41,7 +41,7 @@ mod tests { fn test_clean_content_empty() { let content = " "; let result = clean_content(content); - assert_eq!(result.is_ok(), false); + assert!(!result.is_ok()); } #[test] diff --git a/src/validators/profiles.rs b/src/validators/profiles.rs index 386fd48..66710af 100644 --- a/src/validators/profiles.rs +++ b/src/validators/profiles.rs @@ -194,6 +194,6 @@ mod tests { ..Default::default() }; let result = clean_profile_create_data(&mut profile_data); - assert_eq!(result.is_ok(), true); + assert!(result.is_ok()); } } diff --git a/src/validators/users.rs b/src/validators/users.rs index 6db4f3c..2869c78 100644 --- a/src/validators/users.rs +++ b/src/validators/users.rs @@ -21,8 +21,8 @@ mod tests { #[test] fn test_validate_local_username() { let result_1 = validate_local_username("name_1"); - assert_eq!(result_1.is_ok(), true); + assert!(result_1.is_ok()); let result_2 = validate_local_username("name&"); - assert_eq!(result_2.is_ok(), false); + assert!(!result_2.is_ok()); } }