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/tests/account_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn lock_account(app: &TestApp, user_id: i32, until: Option<NaiveDateTime>)
use diesel::prelude::*;
use diesel_async::RunQueryDsl;

let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

diesel::update(users::table)
.set((
Expand Down
4 changes: 2 additions & 2 deletions src/tests/blocked_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn test_non_blocked_download_route() {
.with_user()
.await;

let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("foo", user.as_model().id)
.version(VersionBuilder::new("1.0.0"))
Expand All @@ -37,7 +37,7 @@ async fn test_blocked_download_route() {
.with_user()
.await;

let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("foo", user.as_model().id)
.version(VersionBuilder::new("1.0.0"))
Expand Down
2 changes: 1 addition & 1 deletion src/tests/dump_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static PATH_DATE_RE: LazyLock<Regex> =
#[tokio::test(flavor = "multi_thread")]
async fn test_dump_db_job() {
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("test-crate", token.as_model().user_id)
.expect_build(&mut conn)
Expand Down
6 changes: 3 additions & 3 deletions src/tests/github_secret_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn github_secret_alert_revokes_token() {
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Ensure no emails were sent up to this point
assert_eq!(app.emails().await.len(), 0);
Expand Down Expand Up @@ -106,7 +106,7 @@ async fn github_secret_alert_for_revoked_token() {
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Ensure no emails were sent up to this point
assert_eq!(app.emails().await.len(), 0);
Expand Down Expand Up @@ -170,7 +170,7 @@ async fn github_secret_alert_for_unknown_token() {
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Ensure no emails were sent up to this point
assert_eq!(app.emails().await.len(), 0);
Expand Down
9 changes: 4 additions & 5 deletions src/tests/issues/issue1205.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ async fn test_issue_1205() -> anyhow::Result<()> {
.with_token()
.await;

let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

let krate = CrateBuilder::new(CRATE_NAME, user.as_model().id)
.expect_build(&mut async_conn)
.expect_build(&mut conn)
.await;

let response = user
Expand All @@ -27,7 +26,7 @@ async fn test_issue_1205() -> anyhow::Result<()> {
assert_eq!(response.status(), StatusCode::OK);
assert_snapshot!(response.text(), @r#"{"msg":"team github:rustaudio:owners has been added as an owner of crate deepspeech-sys","ok":true}"#);

let owners = krate.owners(&mut conn)?;
let owners = krate.async_owners(&mut conn).await?;
assert_eq!(owners.len(), 2);
assert_eq!(owners[0].login(), "foo");
assert_eq!(owners[1].login(), "github:rustaudio:owners");
Expand All @@ -38,7 +37,7 @@ async fn test_issue_1205() -> anyhow::Result<()> {
assert_eq!(response.status(), StatusCode::OK);
assert_snapshot!(response.text(), @r#"{"msg":"team github:rustaudio:cratesio-push has been added as an owner of crate deepspeech-sys","ok":true}"#);

let owners = krate.owners(&mut conn)?;
let owners = krate.async_owners(&mut conn).await?;
assert_eq!(owners.len(), 2);
assert_eq!(owners[0].login(), "foo");
assert_eq!(owners[1].login(), "github:rustaudio:cratesio-push");
Expand Down
16 changes: 9 additions & 7 deletions src/tests/issues/issue2736.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::tests::builders::CrateBuilder;
use crate::tests::util::{RequestHelper, TestApp};
use crates_io_database::schema::{crate_owners, users};
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
use http::StatusCode;
use insta::assert_snapshot;

/// See <https://github.com/rust-lang/crates.io/issues/2736>.
#[tokio::test(flavor = "multi_thread")]
async fn test_issue_2736() -> anyhow::Result<()> {
let (app, _) = TestApp::full().empty().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// - A user had a GitHub account named, let's say, `foo`
let foo1 = app.db_new_user("foo").await;
Expand All @@ -20,7 +20,7 @@ async fn test_issue_2736() -> anyhow::Result<()> {
let someone_else = app.db_new_user("someone_else").await;

let krate = CrateBuilder::new("crate1", someone_else.as_model().id)
.expect_build(&mut async_conn)
.expect_build(&mut conn)
.await;

diesel::insert_into(crate_owners::table)
Expand All @@ -31,7 +31,8 @@ async fn test_issue_2736() -> anyhow::Result<()> {
owner_kind: OwnerKind::User,
email_notifications: true,
})
.execute(&mut conn)?;
.execute(&mut conn)
.await?;

// - `foo` deleted their GitHub account (but crates.io has no real knowledge of this)
// - `foo` recreated their GitHub account with the same username (because it was still available), but in this situation GitHub assigns them a new ID
Expand All @@ -41,13 +42,14 @@ async fn test_issue_2736() -> anyhow::Result<()> {
let github_ids = users::table
.filter(users::gh_login.eq("foo"))
.select(users::gh_id)
.load::<i32>(&mut conn)?;
.load::<i32>(&mut conn)
.await?;

assert_eq!(github_ids.len(), 2);
assert_ne!(github_ids[0], github_ids[1]);

// - The new `foo` account is NOT an owner of the crate
let owners = krate.owners(&mut conn)?;
let owners = krate.async_owners(&mut conn).await?;
assert_eq!(owners.len(), 2);
assert_none!(owners.iter().find(|o| o.id() == foo2.as_model().id));

Expand All @@ -56,7 +58,7 @@ async fn test_issue_2736() -> anyhow::Result<()> {
assert_eq!(response.status(), StatusCode::OK);
assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#);

let owners = krate.owners(&mut conn)?;
let owners = krate.async_owners(&mut conn).await?;
assert_eq!(owners.len(), 1);
assert_eq!(owners[0].id(), someone_else.as_model().id);

Expand Down
6 changes: 3 additions & 3 deletions src/tests/krate/following.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_unauthenticated_requests() {
const CRATE_NAME: &str = "foo";

let (app, anon, user) = TestApp::init().with_user().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new(CRATE_NAME, user.as_model().id)
.expect_build(&mut conn)
Expand Down Expand Up @@ -64,7 +64,7 @@ async fn test_following() {
const CRATE_NAME: &str = "foo_following";

let (app, _, user) = TestApp::init().with_user().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new(CRATE_NAME, user.as_model().id)
.expect_build(&mut conn)
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn test_api_token_auth() {
const CRATE_NOT_TO_FOLLOW: &str = "another_crate";

let (app, _, user, token) = TestApp::init().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;
let api_token = token.as_model();

CrateBuilder::new(CRATE_TO_FOLLOW, api_token.user_id)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/audit_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async fn publish_records_an_audit_action() {

let (app, anon, _, token) = TestApp::full().with_token().await;

let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;
assert!(VersionOwnerAction::all(&mut conn).await.unwrap().is_empty());

// Upload a new crate, putting it in the git index
Expand Down
4 changes: 2 additions & 2 deletions src/tests/krate/publish/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use insta::assert_snapshot;
#[tokio::test(flavor = "multi_thread")]
async fn new_wrong_token() {
let (app, anon, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Try to publish without a token
let crate_to_publish = PublishBuilder::new("foo", "1.0.0");
Expand All @@ -36,7 +36,7 @@ async fn new_wrong_token() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_wrong_user() {
let (app, _, user) = TestApp::full().with_user().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Create the foo_wrong crate with one user
CrateBuilder::new("foo_wrong", user.as_model().id)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/krate/publish/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use insta::{assert_json_snapshot, assert_snapshot};
#[tokio::test(flavor = "multi_thread")]
async fn new_krate() {
let (app, _, user) = TestApp::full().with_user().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

let crate_to_publish = PublishBuilder::new("foo_new", "1.0.0");
let response = user.publish_crate(crate_to_publish).await;
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn new_krate_twice_alt() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_duplicate_version() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database and then we'll try to publish the same version
CrateBuilder::new("foo_dupe", user.as_model().id)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use insta::{assert_json_snapshot, assert_snapshot};
#[tokio::test(flavor = "multi_thread")]
async fn good_categories() {
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

insert_into(categories::table)
.values(new_category("Category 1", "cat1", "Category 1 crates"))
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/deleted_crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use insta::assert_snapshot;
#[tokio::test(flavor = "multi_thread")]
async fn test_recently_deleted_crate_with_same_name() -> anyhow::Result<()> {
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

let now = Utc::now();
let created_at = now - Duration::hours(24);
Expand Down
28 changes: 14 additions & 14 deletions src/tests/krate/publish/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn invalid_dependency_name() {
#[tokio::test(flavor = "multi_thread")]
async fn new_with_renamed_dependency() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -38,7 +38,7 @@ async fn new_with_renamed_dependency() {
#[tokio::test(flavor = "multi_thread")]
async fn invalid_dependency_rename() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -59,7 +59,7 @@ async fn invalid_dependency_rename() {
#[tokio::test(flavor = "multi_thread")]
async fn invalid_dependency_name_starts_with_digit() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -80,7 +80,7 @@ async fn invalid_dependency_name_starts_with_digit() {
#[tokio::test(flavor = "multi_thread")]
async fn invalid_dependency_name_contains_unicode_chars() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -101,7 +101,7 @@ async fn invalid_dependency_name_contains_unicode_chars() {
#[tokio::test(flavor = "multi_thread")]
async fn invalid_too_long_dependency_name() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -122,7 +122,7 @@ async fn invalid_too_long_dependency_name() {
#[tokio::test(flavor = "multi_thread")]
async fn empty_dependency_name() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -143,7 +143,7 @@ async fn empty_dependency_name() {
#[tokio::test(flavor = "multi_thread")]
async fn new_with_underscore_renamed_dependency() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new-krate can depend on it
CrateBuilder::new("package-name", user.as_model().id)
Expand All @@ -164,7 +164,7 @@ async fn new_krate_with_dependency() {
use crate::tests::routes::crates::versions::dependencies::Deps;

let (app, anon, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new_dep can depend on it
// The name choice of `foo-dep` is important! It has the property of
Expand Down Expand Up @@ -197,7 +197,7 @@ async fn new_krate_with_dependency() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_with_broken_dependency_requirement() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new_dep can depend on it
// The name choice of `foo-dep` is important! It has the property of
Expand All @@ -219,7 +219,7 @@ async fn new_krate_with_broken_dependency_requirement() {
#[tokio::test(flavor = "multi_thread")]
async fn reject_new_krate_with_non_exact_dependency() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("foo-dep", user.as_model().id)
.expect_build(&mut conn)
Expand All @@ -239,7 +239,7 @@ async fn reject_new_krate_with_non_exact_dependency() {
#[tokio::test(flavor = "multi_thread")]
async fn new_crate_allow_empty_alternative_registry_dependency() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("foo-dep", user.as_model().id)
.expect_build(&mut conn)
Expand Down Expand Up @@ -268,7 +268,7 @@ async fn reject_new_crate_with_alternative_registry_dependency() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_with_wildcard_dependency() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert a crate directly into the database so that new_wild can depend on it
CrateBuilder::new("foo_wild", user.as_model().id)
Expand Down Expand Up @@ -303,7 +303,7 @@ async fn new_krate_dependency_missing() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_sorts_deps() {
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

// Insert crates directly into the database so that two-deps can depend on it
CrateBuilder::new("dep-a", user.as_model().id)
Expand Down Expand Up @@ -348,7 +348,7 @@ async fn test_dep_limit() {
.with_token()
.await;

let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("dep-a", user.as_model().id)
.expect_build(&mut conn)
Expand Down
4 changes: 2 additions & 2 deletions src/tests/krate/publish/emails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use insta::assert_snapshot;
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_without_any_email_fails() {
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

delete(emails::table).execute(&mut conn).await.unwrap();

Expand All @@ -27,7 +27,7 @@ async fn new_krate_without_any_email_fails() {
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_with_unverified_email_fails() {
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;
let mut conn = app.db_conn().await;

update(emails::table)
.set((emails::verified.eq(false),))
Expand Down
Loading