feat: define interface to del user and repository

This commit is contained in:
Aravinth Manivannan 2022-05-17 16:14:52 +05:30
parent dcb11a4d11
commit 5481055e45
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 37 additions and 0 deletions

View file

@ -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<bool>;
/// 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<bool>;

View file

@ -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