Can now add database to store.
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
			
		||||
pub struct Database;
 | 
			
		||||
 | 
			
		||||
impl Database {
 | 
			
		||||
    fn new() -> Self {
 | 
			
		||||
    pub fn new() -> Self {
 | 
			
		||||
        Self {}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ pub enum FromCache {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Debug)]
 | 
			
		||||
struct Data<D> {
 | 
			
		||||
pub struct Data<D> {
 | 
			
		||||
    id: Option<String>,
 | 
			
		||||
    data: Option<D>,
 | 
			
		||||
}
 | 
			
		||||
@@ -48,6 +48,13 @@ impl<D> Data<D> {
 | 
			
		||||
            data: None,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn from_data(data: D) -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            id: None,
 | 
			
		||||
            data: Some(data),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,15 @@ impl Store {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn add(&mut self, name: &str) {
 | 
			
		||||
        let storage = Data::from_data(Database::new());
 | 
			
		||||
        self.data.insert(name.to_string(), storage);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn get(&self, name: &str) -> Option<&Data<Database>> {
 | 
			
		||||
        self.data.get(name)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn list(&self) -> Vec<String> {
 | 
			
		||||
        Vec::new()
 | 
			
		||||
    }
 | 
			
		||||
@@ -20,7 +29,7 @@ impl Store {
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod storage {
 | 
			
		||||
    use super::*;
 | 
			
		||||
    use super::{super::MTTError, *};
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn create_new() {
 | 
			
		||||
@@ -28,4 +37,22 @@ mod storage {
 | 
			
		||||
        let expected: Vec<String> = Vec::new();
 | 
			
		||||
        assert_eq!(store.list(), expected);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn add_database() {
 | 
			
		||||
        let mut store = Store::new();
 | 
			
		||||
        let name = "Melvin";
 | 
			
		||||
        store.add(name);
 | 
			
		||||
        let output = store.get(name);
 | 
			
		||||
        assert!(output.is_some(), "Get returned none.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn get_bad_database() -> Result<(), MTTError> {
 | 
			
		||||
        let store = Store::new();
 | 
			
		||||
        match store.get("missing") {
 | 
			
		||||
            Some(_) => Err(MTTError::new("Should have returned None.")),
 | 
			
		||||
            None => Ok(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user