Skip to content

Commit afde7f9

Browse files
committed
typosquat/test_util: Remove duplicate add_crate_to_team() fn
This already exists with a slightly similar name, so we might as well use it :D
1 parent a8e1188 commit afde7f9

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn new_team(login: &str) -> NewTeam<'_> {
111111
.build()
112112
}
113113

114-
fn add_team_to_crate(
114+
pub fn add_team_to_crate(
115115
t: &Team,
116116
krate: &Crate,
117117
u: &User,

src/typosquat/database.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ impl From<crate::models::Owner> for Owner {
174174
#[cfg(test)]
175175
mod tests {
176176
use super::*;
177+
use crate::tests::add_team_to_crate;
177178
use crate::typosquat::test_util::faker;
178179
use crates_io_test_db::TestDatabase;
179180
use thiserror::Error;
@@ -194,8 +195,8 @@ mod tests {
194195

195196
// Let's set up a team that owns both b and c, but not a.
196197
let not_the_a_team = faker::team(&mut conn, "org", "team")?;
197-
faker::add_crate_to_team(&mut conn, &user_b, &top_b, &not_the_a_team)?;
198-
faker::add_crate_to_team(&mut conn, &user_b, &not_top_c, &not_the_a_team)?;
198+
add_team_to_crate(&not_the_a_team, &top_b, &user_b, &mut conn)?;
199+
add_team_to_crate(&not_the_a_team, &not_top_c, &user_b, &mut conn)?;
199200

200201
let mut async_conn = test_db.async_connect().await;
201202
let top_crates = TopCrates::new(&mut async_conn, 2).await?;

src/typosquat/test_util.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,15 @@ use diesel::{prelude::*, PgConnection};
22

33
use crate::tests::util::github::next_gh_id;
44
use crate::{
5-
models::{Crate, CrateOwner, NewTeam, NewUser, OwnerKind, Team, User},
6-
schema::{crate_owners, users},
5+
models::{Crate, NewTeam, NewUser, Team, User},
6+
schema::users,
77
};
88

99
pub mod faker {
1010
use super::*;
1111
use crate::tests::builders::CrateBuilder;
1212
use anyhow::anyhow;
1313

14-
pub fn add_crate_to_team(
15-
conn: &mut PgConnection,
16-
user: &User,
17-
krate: &Crate,
18-
team: &Team,
19-
) -> anyhow::Result<()> {
20-
// We have to do a bunch of this by hand, since normally adding a team owner triggers
21-
// various checks.
22-
diesel::insert_into(crate_owners::table)
23-
.values(&CrateOwner {
24-
crate_id: krate.id,
25-
owner_id: team.id,
26-
created_by: user.id,
27-
owner_kind: OwnerKind::Team,
28-
email_notifications: true,
29-
})
30-
.execute(conn)?;
31-
32-
Ok(())
33-
}
34-
3514
pub fn crate_and_version(
3615
conn: &mut PgConnection,
3716
name: &str,

0 commit comments

Comments
 (0)