Replace .expect() with .unwrap()

This commit is contained in:
netbrum 2024-09-30 23:00:11 +02:00
parent 23ac0c1b86
commit 986788ac3e
5 changed files with 15 additions and 38 deletions

View File

@ -69,6 +69,7 @@ impl Claims {
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
mod tests { mod tests {
use crate::{claims::Claims, context::LemmyContext}; use crate::{claims::Claims, context::LemmyContext};
@ -94,9 +95,7 @@ mod tests {
async fn test_should_not_validate_user_token_after_password_change() -> LemmyResult<()> { async fn test_should_not_validate_user_token_after_password_change() -> LemmyResult<()> {
let pool_ = build_db_pool_for_tests().await; let pool_ = build_db_pool_for_tests().await;
let pool = &mut (&pool_).into(); let pool = &mut (&pool_).into();
let secret = Secret::init(pool) let secret = Secret::init(pool).await?.unwrap();
.await?
.expect("Couldn't initialize secrets");
let context = LemmyContext::create( let context = LemmyContext::create(
pool_.clone(), pool_.clone(),
ClientBuilder::new(Client::default()).build(), ClientBuilder::new(Client::default()).build(),

View File

@ -120,6 +120,7 @@ pub(crate) async fn get_apub_community_featured(
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
pub(crate) mod tests { pub(crate) mod tests {
use super::*; use super::*;
@ -181,9 +182,7 @@ pub(crate) mod tests {
} }
async fn decode_response<T: DeserializeOwned>(res: HttpResponse) -> LemmyResult<T> { async fn decode_response<T: DeserializeOwned>(res: HttpResponse) -> LemmyResult<T> {
let body = to_bytes(res.into_body()) let body = to_bytes(res.into_body()).await.unwrap();
.await
.expect("Couldn't turn response body into bytes");
let body = std::str::from_utf8(&body)?; let body = std::str::from_utf8(&body)?;
Ok(serde_json::from_str(body)?) Ok(serde_json::from_str(body)?)
} }

View File

@ -58,6 +58,7 @@ impl ReceivedActivity {
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
mod tests { mod tests {
use super::*; use super::*;
@ -77,9 +78,7 @@ mod tests {
// inserting activity should only work once // inserting activity should only work once
ReceivedActivity::create(pool, &ap_id).await?; ReceivedActivity::create(pool, &ap_id).await?;
ReceivedActivity::create(pool, &ap_id) ReceivedActivity::create(pool, &ap_id).await.unwrap_err();
.await
.expect_err("Inserting activity worked twice");
Ok(()) Ok(())
} }

View File

@ -222,6 +222,7 @@ impl<T: DataSource> CommunityInboxCollector<T> {
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
#[expect(clippy::indexing_slicing)] #[expect(clippy::indexing_slicing)]
mod tests { mod tests {
use super::*; use super::*;
@ -333,14 +334,8 @@ mod tests {
.expect_get_instance_followed_community_inboxes() .expect_get_instance_followed_community_inboxes()
.return_once(move |_, _| { .return_once(move |_, _| {
Ok(vec![ Ok(vec![
( (community_id, Url::parse(url1).unwrap().into()),
community_id, (community_id, Url::parse(url2).unwrap().into()),
Url::parse(url1).expect("Couldn't parse url").into(),
),
(
community_id,
Url::parse(url2).expect("Coudln't parse url").into(),
),
]) ])
}); });
@ -437,9 +432,7 @@ mod tests {
.return_once(move |_, _| { .return_once(move |_, _| {
Ok(vec![( Ok(vec![(
community_id, community_id,
Url::parse(subdomain_inbox) Url::parse(subdomain_inbox).unwrap().into(),
.expect("Couldn't parse url")
.into(),
)]) )])
}); });
@ -493,25 +486,13 @@ mod tests {
.returning(move |_, last_fetch| { .returning(move |_, last_fetch| {
if last_fetch == Utc.timestamp_nanos(0) { if last_fetch == Utc.timestamp_nanos(0) {
Ok(vec![ Ok(vec![
( (community_id1, Url::parse(user1_inbox_str).unwrap().into()),
community_id1, (community_id2, Url::parse(user2_inbox_str).unwrap().into()),
Url::parse(user1_inbox_str)
.expect("Couldn't parse url")
.into(),
),
(
community_id2,
Url::parse(user2_inbox_str)
.expect("Couldn't parse url")
.into(),
),
]) ])
} else { } else {
Ok(vec![( Ok(vec![(
community_id3, community_id3,
Url::parse(user3_inbox_str) Url::parse(user3_inbox_str).unwrap().into(),
.expect("Coudln't parse url")
.into(),
)]) )])
} }
}); });

View File

@ -97,6 +97,7 @@ where
} }
#[cfg(test)] #[cfg(test)]
#[expect(clippy::unwrap_used)]
mod tests { mod tests {
use super::*; use super::*;
@ -128,9 +129,7 @@ mod tests {
let pool_ = build_db_pool_for_tests().await; let pool_ = build_db_pool_for_tests().await;
let pool = &mut (&pool_).into(); let pool = &mut (&pool_).into();
let secret = Secret::init(pool) let secret = Secret::init(pool).await?.unwrap();
.await?
.expect("Couldn't initialize secrets.");
let context = LemmyContext::create( let context = LemmyContext::create(
pool_.clone(), pool_.clone(),