Add unit tests for the services

This commit is contained in:
Simon Goller 2024-04-27 00:03:15 +02:00
parent 926ac006e7
commit 3b20d12ba1
9 changed files with 231 additions and 12 deletions

View file

@ -6,5 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-trait = "0.1.80"
mockall = "0.12.1"
thiserror = "1.0.59"
uuid = "1.8"

View file

@ -1,5 +1,7 @@
use std::{future::Future, sync::Arc};
use std::sync::Arc;
use async_trait::async_trait;
use mockall::automock;
use thiserror::Error;
#[derive(Error, Debug)]
@ -8,14 +10,14 @@ pub enum DaoError {
DatabaseQueryError(#[from] Box<dyn std::error::Error>),
}
#[automock]
#[async_trait]
pub trait HelloDao {
fn get_hello(&self) -> impl Future<Output = Result<Arc<str>, DaoError>> + Send;
async fn get_hello(&self) -> Result<Arc<str>, DaoError>;
}
#[automock]
#[async_trait]
pub trait PermissionDao {
fn has_privilege(
&self,
user: &str,
privilege: &str,
) -> impl Future<Output = Result<bool, DaoError>> + Send;
async fn has_privilege(&self, user: &str, privilege: &str) -> Result<bool, DaoError>;
}