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

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

28 changes: 23 additions & 5 deletions src/db/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ pub async fn delete_version(
}

async fn get_id(conn: &mut sqlx::PgConnection, name: &str) -> Result<i32> {
Ok(
sqlx::query_scalar!("SELECT id FROM crates WHERE name = $1", name)
.fetch_optional(&mut *conn)
.await?
.ok_or_else(|| CrateDeletionError::MissingCrate(name.into()))?,
Ok(sqlx::query_scalar!(
"SELECT id FROM crates WHERE normalize_crate_name(name) = normalize_crate_name($1)",
name
)
.fetch_optional(&mut *conn)
.await?
.ok_or_else(|| CrateDeletionError::MissingCrate(name.into()))?)
}

// metaprogramming!
Expand Down Expand Up @@ -233,6 +234,23 @@ mod tests {
.is_some())
}

#[test]
fn test_get_id_uses_normalization() {
async_wrapper(|env| async move {
env.async_fake_release()
.await
.name("Some_Package")
.version("1.0.0")
.create_async()
.await?;

let mut conn = env.async_db().await.async_conn().await;
assert!(get_id(&mut conn, "some-package").await.is_ok());

Ok(())
})
}

#[test_case(true)]
#[test_case(false)]
fn test_delete_crate(archive_storage: bool) {
Expand Down
Loading