clean warnings and add tests
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
#[cfg(test)]
|
||||
use mockall::{automock, mock, predicate::*};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::LinkedList;
|
||||
use std::fs;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
@@ -16,12 +12,7 @@ const ALLOW_PATH: &str = "allow_users";
|
||||
#[cfg(debug_assertions)]
|
||||
const POLE_PATH: &str = "allow_pole";
|
||||
|
||||
static mut LIST_IDS: Lazy<Mutex<LinkedList<String>>> =
|
||||
Lazy::new(|| Mutex::new(read_ids(ALLOW_PATH)));
|
||||
|
||||
static mut LIST_POLE_IDS: Lazy<Mutex<LinkedList<String>>> =
|
||||
Lazy::new(|| Mutex::new(read_ids(POLE_PATH)));
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn read_ids<'a>(path: &str) -> LinkedList<String> {
|
||||
let content = fs::read_to_string(path).expect("Something went wrong reading the file");
|
||||
content
|
||||
@@ -31,12 +22,22 @@ fn read_ids<'a>(path: &str) -> LinkedList<String> {
|
||||
.collect::<LinkedList<String>>()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn read_ids<'a>(path: &str) -> LinkedList<String> {
|
||||
let mut ret = LinkedList::new();
|
||||
ret.push_front("id_1".to_string());
|
||||
ret.push_front("id_2".to_string());
|
||||
if !path.eq(POLE_PATH) {
|
||||
ret.push_front("id_3".to_string());
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub struct GroupPermissions {
|
||||
aproved_groups: RwLock<LinkedList<String>>,
|
||||
party_groups: RwLock<LinkedList<String>>,
|
||||
}
|
||||
|
||||
#[cfg_attr(test, automock)]
|
||||
impl GroupPermissions {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -54,20 +55,16 @@ impl GroupPermissions {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare(id: &String) -> bool {
|
||||
let ret: bool;
|
||||
unsafe {
|
||||
ret = LIST_IDS.lock().unwrap().contains(id);
|
||||
log::info!("{}", id);
|
||||
}
|
||||
ret
|
||||
#[test]
|
||||
pub fn test_compare() {
|
||||
let gp = GroupPermissions::new();
|
||||
assert_eq!(true, gp.compare(&"id_3".to_string()));
|
||||
assert_eq!(false, gp.compare(&"id_4".to_string()));
|
||||
}
|
||||
|
||||
pub fn compare_pole(id: &String) -> bool {
|
||||
let ret: bool;
|
||||
unsafe {
|
||||
ret = LIST_POLE_IDS.lock().unwrap().contains(id);
|
||||
log::info!("{}", id);
|
||||
}
|
||||
ret
|
||||
#[test]
|
||||
pub fn test_compare_pole() {
|
||||
let gp = GroupPermissions::new();
|
||||
assert_eq!(true, gp.compar_party(&"id_2".to_string()));
|
||||
assert_eq!(false, gp.compar_party(&"id_3".to_string()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user