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