diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 2d6ef51..3ac9a99 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -133,6 +133,12 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// done only on that forge async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult; + /// delete user + async fn delete_user(&self, username: &str, hostname: &str) -> DBResult<()>; + + /// delete repository + async fn delete_repository(&self, owner: &str, name: &str, hostname: &str) -> DBResult<()>; + /// check if a repository exists. async fn repository_exists(&self, name: &str, owner: &str, hostname: &str) -> DBResult; diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 9e77484..2ad629d 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -33,9 +33,40 @@ pub async fn adding_forge_works<'a, T: SCDatabase>( "forge creation failed, forge existance check failure" ); + // add user db.add_user(&add_user_msg).await.unwrap(); db.add_user(&add_user_msg2).await.unwrap(); + // verify user exists + assert!(db.user_exists(add_user_msg.username, None).await.unwrap()); + assert!(db + .user_exists(add_user_msg.username, Some(add_user_msg.hostname)) + .await + .unwrap()); + + // add repository db.create_repository(&add_repo_msg).await.unwrap(); + // verify repo exists + assert!(db + .repository_exists(add_repo_msg.name, add_repo_msg.owner, add_repo_msg.hostname) + .await + .unwrap()); + // delete repository + db.delete_repository(add_repo_msg.owner, add_repo_msg.name, add_repo_msg.hostname) + .await + .unwrap(); + assert!(!db + .repository_exists(add_repo_msg.name, add_repo_msg.owner, add_repo_msg.hostname) + .await + .unwrap()); + + // delete user + db.delete_user(add_user_msg.username, add_user_msg.hostname) + .await + .unwrap(); + assert!(!db + .user_exists(add_user_msg.username, Some(add_user_msg.hostname)) + .await + .unwrap()); } /// test if all forge type implementations are loaded into DB