use tempfile::tempdir;
use kalavara::master::start as master_start;
use kalavara::volume::start as volume_start;
use std::sync::{Once, ONCE_INIT};
use std::thread;
use std::time::Duration;
static INIT: Once = ONCE_INIT;
fn run() {
let master_data_dir = tempdir().unwrap();
let volume_data_dir = tempdir().unwrap();
thread::spawn(move || {
master_start(6002, master_data_dir.path().to_str().unwrap(), 4, vec![]);
});
thread::sleep(Duration::from_millis(1000));
thread::spawn(move || {
volume_start(
7002,
volume_data_dir.path().to_str().unwrap().to_owned(),
4,
Some("http://localhost:6002".to_string()),
Some("http://localhost:7002".to_string()),
);
});
}
fn setup() {
INIT.call_once(|| {
run();
thread::sleep(Duration::from_millis(1000));
});
}
#[test]
fn test_volume_auto_reg() {
setup();
let res = minreq::put("http://localhost:6002/store/key1")
.with_body("val1")
.send();
assert!(res.is_ok());
assert_eq!(res.unwrap().status_code, 201);
let res = minreq::get("http://localhost:6002/store/key1").send();
assert!(res.is_ok());
let res = res.unwrap();
assert_eq!(res.status_code, 200);
assert_eq!(res.body.trim(), "val1");
let res = minreq::delete("http://localhost:6002/store/key1").send();
assert!(res.is_ok());
assert_eq!(res.unwrap().status_code, 204);
let res = minreq::get("http://localhost:6002/store/key1").send();
assert!(res.is_ok());
assert_eq!(res.unwrap().status_code, 404);
}