add test code to access static global state

This commit is contained in:
Dietmar Maurer 2018-12-20 14:03:42 +01:00
parent fe0e04c69c
commit c2d9b3914a

View File

@ -1,6 +1,8 @@
use failure::*;
//use std::collections::HashMap;
use std::collections::HashMap;
use lazy_static::lazy_static;
use std::sync::{Arc, Mutex};
use crate::api::schema::*;
use crate::api::router::*;
@ -9,6 +11,29 @@ use serde_json::{json, Value};
pub mod config;
mod version;
use crate::backup::datastore::*;
lazy_static!{
static ref datastore_map: Mutex<HashMap<String, Arc<DataStore>>> = Mutex::new(HashMap::new());
}
fn lookup_datastore(name: &str) -> Result<Arc<DataStore>, Error> {
let mut map = datastore_map.lock().unwrap();
if let Some(datastore) = map.get(name) {
return Ok(datastore.clone());
}
if let Ok(datastore) = DataStore::open(name) {
let datastore = Arc::new(datastore);
map.insert(name.to_string(), datastore.clone());
return Ok(datastore);
}
bail!("store not found");
}
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
@ -23,7 +48,6 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error
if let Some(_force) = param["force"].as_bool() {
}
Ok(json!(null))
}