Skip to content

database/tests/schema_details: Use async queries #10010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2024
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: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/crates_io_database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ diesel_full_text_search = "=2.2.0"

[dev-dependencies]
crates_io_test_db = { path = "../crates_io_test_db" }
diesel-async = { version = "=0.5.1", features = ["postgres"] }
tokio = { version = "=1.41.1", features = ["macros", "rt"] }
18 changes: 10 additions & 8 deletions crates/crates_io_database/tests/schema_details.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crates_io_test_db::TestDatabase;
use diesel::prelude::*;
use diesel::sql_types::Text;
use diesel_async::RunQueryDsl;

#[test]
fn all_columns_called_crate_id_have_a_cascading_foreign_key() {
for row in get_fk_constraint_definitions("crate_id") {
#[tokio::test]
async fn all_columns_called_crate_id_have_a_cascading_foreign_key() {
for row in get_fk_constraint_definitions("crate_id").await {
let constraint = match row.constraint {
Some(c) => c,
None => panic!(
Expand All @@ -22,9 +23,9 @@ fn all_columns_called_crate_id_have_a_cascading_foreign_key() {
}
}

#[test]
fn all_columns_called_version_id_have_a_cascading_foreign_key() {
for row in get_fk_constraint_definitions("version_id") {
#[tokio::test]
async fn all_columns_called_version_id_have_a_cascading_foreign_key() {
for row in get_fk_constraint_definitions("version_id").await {
let constraint = match row.constraint {
Some(c) => c,
None => panic!(
Expand Down Expand Up @@ -66,14 +67,15 @@ struct TableNameAndConstraint {
constraint: Option<FkConstraint>,
}

fn get_fk_constraint_definitions(column_name: &str) -> Vec<TableNameAndConstraint> {
async fn get_fk_constraint_definitions(column_name: &str) -> Vec<TableNameAndConstraint> {
use diesel::sql_query;

let test_db = TestDatabase::new();
let mut conn = test_db.connect();
let mut conn = test_db.async_connect().await;

sql_query(include_str!("load_foreign_key_constraints.sql"))
.bind::<Text, _>(column_name)
.load(&mut conn)
.await
.unwrap()
}