diff --git a/src/typosquat/database.rs b/src/typosquat/database.rs index 0f55afec4ab..8dc7f180ecf 100644 --- a/src/typosquat/database.rs +++ b/src/typosquat/database.rs @@ -182,26 +182,24 @@ mod tests { #[tokio::test] async fn top_crates() -> Result<(), Error> { let test_db = TestDatabase::new(); - let mut conn = test_db.connect(); - let mut async_conn = test_db.async_connect().await; + let mut conn = test_db.async_connect().await; // Set up two users. - let user_a = faker::user(&mut conn, "a")?; - let user_b = faker::user(&mut conn, "b")?; + let user_a = faker::user(&mut conn, "a").await?; + let user_b = faker::user(&mut conn, "b").await?; // Set up three crates with various ownership schemes. - let _top_a = faker::crate_and_version(&mut async_conn, "a", "Hello", &user_a, 2).await?; + let _top_a = faker::crate_and_version(&mut conn, "a", "Hello", &user_a, 2).await?; let top_b = - faker::crate_and_version(&mut async_conn, "b", "Yes, this is dog", &user_b, 1).await?; - let not_top_c = - faker::crate_and_version(&mut async_conn, "c", "Unpopular", &user_a, 0).await?; + faker::crate_and_version(&mut conn, "b", "Yes, this is dog", &user_b, 1).await?; + let not_top_c = faker::crate_and_version(&mut conn, "c", "Unpopular", &user_a, 0).await?; // Let's set up a team that owns both b and c, but not a. - let not_the_a_team = faker::team(&mut async_conn, "org", "team").await?; - add_team_to_crate(¬_the_a_team, &top_b, &user_b, &mut async_conn).await?; - add_team_to_crate(¬_the_a_team, ¬_top_c, &user_b, &mut async_conn).await?; + let not_the_a_team = faker::team(&mut conn, "org", "team").await?; + add_team_to_crate(¬_the_a_team, &top_b, &user_b, &mut conn).await?; + add_team_to_crate(¬_the_a_team, ¬_top_c, &user_b, &mut conn).await?; - let top_crates = TopCrates::new(&mut async_conn, 2).await?; + let top_crates = TopCrates::new(&mut conn, 2).await?; // Let's ensure the top crates include what we expect (which is a and b, since we asked for // 2 crates and they're the most downloaded). @@ -215,7 +213,7 @@ mod tests { assert!(!pkg_a.shared_authors(pkg_b.authors())); // Now let's go get package c and pretend it's a new package. - let pkg_c = Crate::from_name(&mut async_conn, "c").await?; + let pkg_c = Crate::from_name(&mut conn, "c").await?; // c _does_ have an author in common with a. assert!(pkg_a.shared_authors(pkg_c.authors())); diff --git a/src/typosquat/test_util.rs b/src/typosquat/test_util.rs index bb25d73092a..2e15b3165ca 100644 --- a/src/typosquat/test_util.rs +++ b/src/typosquat/test_util.rs @@ -1,4 +1,5 @@ -use diesel::{prelude::*, PgConnection}; +use diesel::prelude::*; +use diesel_async::RunQueryDsl; use crate::tests::util::github::next_gh_id; use crate::{ @@ -40,11 +41,12 @@ pub mod faker { Ok(team.async_create_or_update(conn).await?) } - pub fn user(conn: &mut PgConnection, login: &str) -> QueryResult { + pub async fn user(conn: &mut AsyncPgConnection, login: &str) -> QueryResult { let user = NewUser::new(next_gh_id(), login, None, None, "token"); diesel::insert_into(users::table) .values(user) .get_result(conn) + .await } } diff --git a/src/worker/jobs/typosquat.rs b/src/worker/jobs/typosquat.rs index 59ada026cfa..8c42b92f15d 100644 --- a/src/worker/jobs/typosquat.rs +++ b/src/worker/jobs/typosquat.rs @@ -130,12 +130,11 @@ mod tests { async fn integration() -> anyhow::Result<()> { let emails = Emails::new_in_memory(); let test_db = TestDatabase::new(); - let mut conn = test_db.connect(); - let mut async_conn = test_db.async_connect().await; + let mut conn = test_db.async_connect().await; // Set up a user and a popular crate to match against. - let user = faker::user(&mut conn, "a")?; - faker::crate_and_version(&mut async_conn, "my-crate", "It's awesome", &user, 100).await?; + let user = faker::user(&mut conn, "a").await?; + faker::crate_and_version(&mut conn, "my-crate", "It's awesome", &user, 100).await?; // Prime the cache so it only includes the crate we just created. let mut async_conn = test_db.async_connect().await; @@ -143,7 +142,7 @@ mod tests { let cache = Arc::new(cache); // Now we'll create new crates: one problematic, one not so. - let other_user = faker::user(&mut conn, "b")?; + let other_user = faker::user(&mut async_conn, "b").await?; let angel = faker::crate_and_version( &mut async_conn, "innocent-crate",