kanidm/tests/integration_test.rs

104 lines
2.5 KiB
Rust
Raw Normal View History

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;
use rsidm::entry::Entry;
use rsidm::event::EventResult;
use rsidm::log::{self, EventLog, LogEvent};
2018-11-26 07:13:22 +01:00
use rsidm::proto::{CreateRequest, SearchRequest};
use rsidm::server::{self, QueryServer};
// use be;
2018-11-26 07:13:22 +01:00
extern crate reqwest;
extern crate futures;
use futures::future;
2018-11-07 07:35:25 +01:00
use futures::future::Future;
2018-11-26 07:13:22 +01:00
use std::sync::mpsc;
use std::thread;
extern crate tokio;
// use tokio::executor::current_thread::CurrentThread;
2018-09-29 09:54:16 +02:00
// Test external behaviorus of the service.
macro_rules! run_test {
($test_fn:expr) => {{
2018-11-26 07:13:22 +01:00
let (tx, rx) = mpsc::channel();
thread::spawn(|| {
// 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-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-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();
let c = CreateRequest {
entries: Vec::new(),
};
let mut response = client
.post("http://127.0.0.1:8080/create")
.body(serde_json::to_string(&c).unwrap())
.send()
.unwrap();
println!("{:?}", response);
let r: EventResult = serde_json::from_str(response.text().unwrap().as_str()).unwrap();
println!("{:?}", r);
// deserialise the response here
// check it's valid.
()
});
}
/*
#[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
});
}
*/