Files
morethantext-web/src/morethantext/store.rs

59 lines
1.3 KiB
Rust
Raw Normal View History

2023-06-22 11:08:40 -04:00
use super::{Data, Database};
use std::collections::HashMap;
2023-06-20 11:51:32 -04:00
#[derive(Clone, Debug)]
2023-06-22 11:08:40 -04:00
pub struct Store {
data: HashMap<String, Data<Database>>,
}
2023-05-30 00:18:13 -04:00
impl Store {
2023-06-03 15:27:26 -04:00
pub fn new() -> Self {
2023-06-22 11:08:40 -04:00
Self {
data: HashMap::new(),
}
2023-05-30 00:18:13 -04:00
}
2023-06-23 08:30:49 -04:00
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)
}
2023-06-03 15:27:26 -04:00
pub fn list(&self) -> Vec<String> {
2023-05-30 00:18:13 -04:00
Vec::new()
}
}
#[cfg(test)]
mod storage {
2023-06-23 08:30:49 -04:00
use super::{super::MTTError, *};
2023-05-30 00:18:13 -04:00
#[test]
fn create_new() {
let store = Store::new();
let expected: Vec<String> = Vec::new();
assert_eq!(store.list(), expected);
}
2023-06-23 08:30:49 -04:00
#[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(()),
}
}
2023-05-30 00:18:13 -04:00
}