Skip to content

Commit 9a3e35a

Browse files
committed
typosquat/test_util: Use tests::util::github::next_gh_id()
1 parent 7ce9a0e commit 9a3e35a

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub mod tasks;
6060
pub mod team_repo;
6161
mod test_util;
6262
#[cfg(test)]
63-
mod tests;
63+
pub mod tests;
6464
pub mod typosquat;
6565
pub mod util;
6666
pub mod views;

src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod team;
3232
mod token;
3333
mod unhealthy_database;
3434
mod user;
35-
mod util;
35+
pub mod util;
3636
mod version;
3737
mod worker;
3838

src/tests/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub fn encode_session_header(session_key: &cookie::Key, user_id: i32) -> String
8585
/// A collection of helper methods for the 3 authentication types
8686
///
8787
/// Helper methods go through public APIs, and should not modify the database directly
88+
#[allow(async_fn_in_trait)]
8889
pub trait RequestHelper {
8990
fn request_builder(&self, method: Method, path: &str) -> MockRequest;
9091
fn app(&self) -> &TestApp;

src/typosquat/test_util.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use diesel::{prelude::*, PgConnection};
22

3+
use crate::tests::util::github::next_gh_id;
34
use crate::{
45
models::{
56
Crate, CrateOwner, NewCrate, NewTeam, NewUser, NewVersion, Owner, OwnerKind, User, Version,
@@ -10,14 +11,12 @@ use crate::{
1011

1112
pub struct Faker {
1213
emails: Emails,
13-
id: i32,
1414
}
1515

1616
impl Faker {
1717
pub fn new() -> Self {
1818
Self {
1919
emails: Emails::new_in_memory(),
20-
id: Default::default(),
2120
}
2221
}
2322

@@ -83,8 +82,8 @@ impl Faker {
8382
Ok(Owner::Team(
8483
NewTeam::new(
8584
&format!("github:{org}:{team}"),
86-
self.next_id(),
87-
self.next_id(),
85+
next_gh_id(),
86+
next_gh_id(),
8887
Some(team.to_string()),
8988
None,
9089
)
@@ -94,16 +93,11 @@ impl Faker {
9493

9594
pub fn user(&mut self, conn: &mut PgConnection, login: &str) -> anyhow::Result<User> {
9695
Ok(
97-
NewUser::new(self.next_id(), login, None, None, "token").create_or_update(
96+
NewUser::new(next_gh_id(), login, None, None, "token").create_or_update(
9897
None,
9998
&self.emails,
10099
conn,
101100
)?,
102101
)
103102
}
104-
105-
fn next_id(&mut self) -> i32 {
106-
self.id += 1;
107-
self.id
108-
}
109103
}

0 commit comments

Comments
 (0)