Apply clippy suggestions
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Rafael Caricio 2023-04-28 00:01:24 +02:00
parent 406781570c
commit 7281340423
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
28 changed files with 111 additions and 126 deletions

View file

@ -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 {

View file

@ -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());
}
}

View file

@ -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)
assert!(!can_view_post(db_client, None, &post).await.unwrap(),);
assert!(!can_view_post(db_client, Some(&follower), &post)
.await
.unwrap(),
false,
);
assert_eq!(
can_view_post(db_client, Some(&subscriber), &post)
.unwrap(),);
assert!(can_view_post(db_client, Some(&subscriber), &post)
.await
.unwrap(),
true,
);
.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));
}
}

View file

@ -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();

View file

@ -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());
}
}

View file

@ -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)

View file

@ -249,6 +249,6 @@ mod tests {
)
.await
.unwrap();
assert_eq!(is_subscribed, true);
assert!(is_subscribed);
}
}

View file

@ -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 =

View file

@ -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);
}
}

View file

@ -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());
}
}

View file

@ -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]

View file

@ -28,7 +28,7 @@ pub fn parse_identity_proof(
_actor_id: &str,
_attachment: &ActorAttachment,
) -> Result<IdentityProof, ValidationError> {
return Err(ValidationError("incorrect proof type".to_string()));
Err(ValidationError("incorrect proof type".to_string()))
}
pub fn attach_payment_option(

View file

@ -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]);

View file

@ -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()
};

View file

@ -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]

View file

@ -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());
}
}

View file

@ -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);
}
}

View file

@ -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),);
}
}

View file

@ -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());
}
}

View file

@ -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());
}
}

View file

@ -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(), &current_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 {}",

View file

@ -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());
}
}

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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]

View file

@ -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]

View file

@ -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());
}
}

View file

@ -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());
}
}