2018-10-03 13:21:21 +02:00
|
|
|
extern crate actix;
|
|
|
|
use actix::prelude::*;
|
|
|
|
|
|
|
|
extern crate rsidm;
|
2018-11-26 07:13:22 +01:00
|
|
|
use rsidm::config::Configuration;
|
|
|
|
use rsidm::core::create_server_core;
|
2018-12-27 06:22:03 +01:00
|
|
|
use rsidm::proto_v1::{CreateRequest, Entry, Response, SearchRequest, SearchResponse};
|
2018-10-03 13:21:21 +02:00
|
|
|
|
2018-11-26 07:13:22 +01:00
|
|
|
extern crate reqwest;
|
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
extern crate futures;
|
|
|
|
use futures::future;
|
2018-11-07 07:35:25 +01:00
|
|
|
use futures::future::Future;
|
2018-10-03 13:21:21 +02:00
|
|
|
|
2018-11-26 07:13:22 +01:00
|
|
|
use std::sync::mpsc;
|
|
|
|
use std::thread;
|
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
extern crate tokio;
|
|
|
|
|
2018-09-29 09:54:16 +02:00
|
|
|
// Test external behaviorus of the service.
|
|
|
|
|
2018-10-03 13:21:21 +02:00
|
|
|
macro_rules! run_test {
|
|
|
|
($test_fn:expr) => {{
|
2018-11-26 07:13:22 +01:00
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
|
|
|
|
thread::spawn(|| {
|
2018-10-03 13:21:21 +02:00
|
|
|
// setup
|
|
|
|
// Create a server config in memory for use - use test settings
|
|
|
|
// Create a log: In memory - for now it's just stdout
|
2018-09-29 09:54:16 +02:00
|
|
|
|
2018-11-26 07:13:22 +01:00
|
|
|
System::run(move || {
|
|
|
|
let config = Configuration::new();
|
|
|
|
create_server_core(config);
|
|
|
|
|
|
|
|
// This appears to be bind random ...
|
|
|
|
// let srv = srv.bind("127.0.0.1:0").unwrap();
|
|
|
|
let _ = tx.send(System::current());
|
|
|
|
});
|
2018-10-03 13:21:21 +02:00
|
|
|
});
|
2018-11-26 07:13:22 +01:00
|
|
|
let sys = rx.recv().unwrap();
|
|
|
|
System::set_current(sys.clone());
|
|
|
|
|
|
|
|
// Do we need any fixtures?
|
|
|
|
// Yes probably, but they'll need to be futures as well ...
|
|
|
|
// later we could accept fixture as it's own future for re-use
|
|
|
|
$test_fn();
|
|
|
|
|
|
|
|
// We DO NOT need teardown, as sqlite is in mem
|
|
|
|
// let the tables hit the floor
|
|
|
|
let _ = sys.stop();
|
2018-10-03 13:21:21 +02:00
|
|
|
}};
|
2018-09-29 09:54:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-11-26 07:13:22 +01:00
|
|
|
fn test_server_proto() {
|
|
|
|
run_test!(|| {
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
2018-11-27 11:48:21 +01:00
|
|
|
let e: Entry = serde_json::from_str(
|
|
|
|
r#"{
|
|
|
|
"attrs": {
|
|
|
|
"class": ["person"],
|
|
|
|
"name": ["testperson"],
|
|
|
|
"description": ["testperson"],
|
|
|
|
"displayname": ["testperson"]
|
|
|
|
}
|
|
|
|
}"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2018-12-27 06:22:03 +01:00
|
|
|
let c = CreateRequest { entries: vec![e] };
|
2018-11-26 07:13:22 +01:00
|
|
|
|
|
|
|
let mut response = client
|
2018-11-27 11:48:21 +01:00
|
|
|
.post("http://127.0.0.1:8080/v1/create")
|
2018-11-26 07:13:22 +01:00
|
|
|
.body(serde_json::to_string(&c).unwrap())
|
|
|
|
.send()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("{:?}", response);
|
2018-11-27 11:48:21 +01:00
|
|
|
let r: Response = serde_json::from_str(response.text().unwrap().as_str()).unwrap();
|
2018-11-26 07:13:22 +01:00
|
|
|
|
|
|
|
println!("{:?}", r);
|
|
|
|
|
|
|
|
// deserialise the response here
|
|
|
|
// check it's valid.
|
|
|
|
|
|
|
|
()
|
|
|
|
});
|
2018-10-03 13:21:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
#[test]
|
|
|
|
fn test_be_create_user() {
|
2018-11-07 08:27:11 +01:00
|
|
|
run_test!(|log, server: actix::Addr<QueryServer>| {
|
|
|
|
let r1 = server.search();
|
|
|
|
assert!(r1.len() == 0);
|
|
|
|
|
|
|
|
let cr = server.create();
|
|
|
|
assert!(cr.is_ok());
|
|
|
|
|
|
|
|
let r2 = server.search();
|
|
|
|
assert!(r2.len() == 1);
|
|
|
|
|
|
|
|
future::ok(())
|
2018-09-29 09:54:16 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-03 13:21:21 +02:00
|
|
|
*/
|