kanidm/tests/integration_test.rs

73 lines
2 KiB
Rust
Raw Normal View History

extern crate actix;
use actix::prelude::*;
2018-09-29 09:54:16 +02:00
use std::panic;
extern crate rsidm;
use rsidm::log::{self, EventLog, LogEvent};
use rsidm::server::{self, QueryServer};
// use be;
extern crate futures;
use futures::future;
2018-11-07 07:35:25 +01:00
use futures::future::lazy;
use futures::future::Future;
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) => {{
System::run(|| {
// setup
// Create a server config in memory for use - use test settings
// Create a log: In memory - for now it's just stdout
let test_log = log::start();
// Create the db as a temporary, see:
// https://sqlite.org/inmemorydb.html
let test_server = server::start(test_log.clone(), "", 1);
// 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
// For now these can also bypass the FE code
// let fixture_fut = ();
2018-09-29 09:54:16 +02:00
// We have to spawn every test as a future
let fut = $test_fn(test_log, test_server);
2018-09-29 09:54:16 +02:00
// Now chain them ...
// Now append the server shutdown.
2018-11-07 07:35:25 +01:00
let comp_fut = fut.map_err(|_| ()).and_then(|r| {
println!("Stopping actix ...");
actix::System::current().stop();
future::result(Ok(()))
});
2018-09-29 09:54:16 +02:00
// Run the future
tokio::spawn(comp_fut);
// We DO NOT need teardown, as sqlite is in mem
// let the tables hit the floor
});
}};
2018-09-29 09:54:16 +02:00
}
#[test]
fn test_schema() {
2018-11-07 07:35:25 +01:00
run_test!(|log: actix::Addr<EventLog>, server| log.send(LogEvent {
msg: String::from("Test log event")
}));
}
/*
#[test]
fn test_be_create_user() {
run_test!(|log, be, server| {
2018-09-29 09:54:16 +02:00
println!("It works");
});
}
*/