use super::{Data, Database}; use std::collections::HashMap; #[derive(Clone, Debug)] pub struct Store { data: HashMap>, } impl Store { pub fn new() -> Self { Self { data: HashMap::new(), } } 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> { self.data.get(name) } pub fn list(&self) -> Vec { Vec::new() } } #[cfg(test)] mod storage { use super::{super::MTTError, *}; #[test] fn create_new() { let store = Store::new(); let expected: Vec = 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(()), } } }