use crate::error::GarrisonResult;
use crate::stp::GarrisonInterface;
use async_trait::async_trait;
use std::collections::HashMap;
pub struct MockInterface {
permissions: HashMap<String, Vec<String>>,
roles: HashMap<String, Vec<String>>,
}
impl MockInterface {
pub fn new() -> Self {
Self {
permissions: HashMap::new(),
roles: HashMap::new(),
}
}
pub fn with_permission(mut self, login_id: &str, perms: &[&str]) -> Self {
self.permissions.insert(
login_id.to_string(),
perms.iter().map(|s| s.to_string()).collect(),
);
self
}
pub fn with_role(mut self, login_id: &str, roles: &[&str]) -> Self {
self.roles.insert(
login_id.to_string(),
roles.iter().map(|s| s.to_string()).collect(),
);
self
}
}
#[async_trait]
impl GarrisonInterface for MockInterface {
async fn get_permission_list(&self, login_id: &str) -> GarrisonResult<Vec<String>> {
Ok(self.permissions.get(login_id).cloned().unwrap_or_default())
}
async fn get_role_list(&self, login_id: &str) -> GarrisonResult<Vec<String>> {
Ok(self.roles.get(login_id).cloned().unwrap_or_default())
}
}