Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub mod tasks;
pub mod team_repo;
mod test_util;
#[cfg(test)]
mod tests;
pub mod tests;
pub mod typosquat;
pub mod util;
pub mod views;
Expand Down
12 changes: 5 additions & 7 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
EncodableOwner, EncodableVersion, GoodCrate,
},
};
use std::sync::atomic::{AtomicUsize, Ordering};

use crate::tests::util::github::next_gh_id;
use diesel::prelude::*;

mod account_lock;
Expand All @@ -32,7 +32,7 @@ mod team;
mod token;
mod unhealthy_database;
mod user;
mod util;
pub mod util;
mod version;
mod worker;

Expand Down Expand Up @@ -86,11 +86,9 @@ pub struct OkBool {
ok: bool,
}

static NEXT_GH_ID: AtomicUsize = AtomicUsize::new(0);

fn new_user(login: &str) -> NewUser<'_> {
NewUser {
gh_id: NEXT_GH_ID.fetch_add(1, Ordering::SeqCst) as i32,
gh_id: next_gh_id(),
gh_login: login,
name: None,
gh_avatar: None,
Expand All @@ -100,8 +98,8 @@ fn new_user(login: &str) -> NewUser<'_> {

fn new_team(login: &str) -> NewTeam<'_> {
NewTeam {
org_id: NEXT_GH_ID.fetch_add(1, Ordering::SeqCst) as i32,
github_id: NEXT_GH_ID.fetch_add(1, Ordering::SeqCst) as i32,
org_id: next_gh_id(),
github_id: next_gh_id(),
login,
name: None,
avatar: None,
Expand Down
3 changes: 2 additions & 1 deletion src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use std::net::SocketAddr;
use tower::ServiceExt;

mod chaosproxy;
mod github;
pub mod github;
pub mod insta;
pub mod matchers;
mod mock_request;
Expand Down Expand Up @@ -85,6 +85,7 @@ pub fn encode_session_header(session_key: &cookie::Key, user_id: i32) -> String
/// A collection of helper methods for the 3 authentication types
///
/// Helper methods go through public APIs, and should not modify the database directly
#[allow(async_fn_in_trait)]
pub trait RequestHelper {
fn request_builder(&self, method: Method, path: &str) -> MockRequest;
fn app(&self) -> &TestApp;
Expand Down
7 changes: 7 additions & 0 deletions src/tests/util/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use crates_io_github::{
GitHubTeam, GitHubTeamMembership, GithubUser,
};
use oauth2::AccessToken;
use std::sync::atomic::{AtomicUsize, Ordering};

static NEXT_GH_ID: AtomicUsize = AtomicUsize::new(0);

pub fn next_gh_id() -> i32 {
NEXT_GH_ID.fetch_add(1, Ordering::SeqCst) as i32
}

pub(crate) const MOCK_GITHUB_DATA: MockData = MockData {
orgs: &[MockOrg {
Expand Down
14 changes: 4 additions & 10 deletions src/typosquat/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use diesel::{prelude::*, PgConnection};

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

pub struct Faker {
emails: Emails,
id: i32,
}

impl Faker {
pub fn new() -> Self {
Self {
emails: Emails::new_in_memory(),
id: Default::default(),
}
}

Expand Down Expand Up @@ -83,8 +82,8 @@ impl Faker {
Ok(Owner::Team(
NewTeam::new(
&format!("github:{org}:{team}"),
self.next_id(),
self.next_id(),
next_gh_id(),
next_gh_id(),
Some(team.to_string()),
None,
)
Expand All @@ -94,16 +93,11 @@ impl Faker {

pub fn user(&mut self, conn: &mut PgConnection, login: &str) -> anyhow::Result<User> {
Ok(
NewUser::new(self.next_id(), login, None, None, "token").create_or_update(
NewUser::new(next_gh_id(), login, None, None, "token").create_or_update(
None,
&self.emails,
conn,
)?,
)
}

fn next_id(&mut self) -> i32 {
self.id += 1;
self.id
}
}