mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 04:27:02 +01:00
Begin adding query server tests
This commit is contained in:
parent
a684b1095a
commit
58e45149d4
|
@ -35,6 +35,8 @@ impl BackendAuditEvent {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct IdEntry {
|
||||
// FIXME: This should be u64, but sqlite uses i32 ...
|
||||
// Should we use a bigint pk and just be done?
|
||||
id: i32,
|
||||
data: String,
|
||||
}
|
||||
|
@ -151,6 +153,12 @@ impl Backend {
|
|||
// Alloc a vec for the entries.
|
||||
// FIXME: Make this actually a good size for the result set ...
|
||||
// FIXME: Actually compute indexes here.
|
||||
// So to make this use indexes, we can use the filter type and
|
||||
// destructure it to work out what we need to actually search (if
|
||||
// possible) to create the candidate set.
|
||||
// Unlike DS, even if we don't get the index back, we can just pass
|
||||
// to the in-memory filter test and be done.
|
||||
|
||||
let mut raw_entries: Vec<String> = Vec::new();
|
||||
{
|
||||
// Actually do a search now!
|
||||
|
|
|
@ -185,4 +185,3 @@ mod tests {
|
|||
assert!(!e.pres("name"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,25 +43,15 @@ impl Filter {
|
|||
// Go through the filter components and check them in the entry.
|
||||
// This is recursive!!!!
|
||||
match self {
|
||||
Filter::Eq(_, _) => {
|
||||
false
|
||||
}
|
||||
Filter::Sub(_, _) => {
|
||||
false
|
||||
}
|
||||
Filter::Eq(_, _) => false,
|
||||
Filter::Sub(_, _) => false,
|
||||
Filter::Pres(attr) => {
|
||||
// Given attr, is is present in the entry?
|
||||
e.pres(attr.as_str())
|
||||
}
|
||||
Filter::Or(_) => {
|
||||
false
|
||||
}
|
||||
Filter::And(_) => {
|
||||
false
|
||||
}
|
||||
Filter::Not(_) => {
|
||||
false
|
||||
}
|
||||
Filter::Or(_) => false,
|
||||
Filter::And(_) => false,
|
||||
Filter::Not(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,4 +85,67 @@ impl Handler<SearchEvent> for QueryServer {
|
|||
}
|
||||
}
|
||||
|
||||
impl Handler<CreateEvent> for QueryServer {
|
||||
type Result = Result<EventResult, ()>;
|
||||
|
||||
fn handle(&mut self, msg: CreateEvent, _: &mut Self::Context) -> Self::Result {
|
||||
log_event!(self.log, "Begin event {:?}", msg);
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
// Auth requests? How do we structure these ...
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate actix;
|
||||
use actix::prelude::*;
|
||||
|
||||
extern crate futures;
|
||||
use futures::future;
|
||||
use futures::future::lazy;
|
||||
use futures::future::Future;
|
||||
|
||||
extern crate tokio;
|
||||
|
||||
use super::super::be::Backend;
|
||||
use super::super::log::{self, EventLog, LogEvent};
|
||||
use super::super::server::QueryServer;
|
||||
|
||||
macro_rules! run_test {
|
||||
($test_fn:expr) => {{
|
||||
System::run(|| {
|
||||
let test_log = log::start();
|
||||
|
||||
let mut be = Backend::new(test_log.clone(), "");
|
||||
let mut test_server = QueryServer::new(test_log.clone(), be);
|
||||
|
||||
// Could wrap another future here for the future::ok bit...
|
||||
let fut = $test_fn(test_log, test_server);
|
||||
let comp_fut = fut.map_err(|()| ()).and_then(|r| {
|
||||
println!("Stopping actix ...");
|
||||
actix::System::current().stop();
|
||||
future::result(Ok(()))
|
||||
});
|
||||
|
||||
tokio::spawn(comp_fut);
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_be_create_user() {
|
||||
run_test!(|log, mut server: QueryServer| {
|
||||
let r1 = server.search().unwrap();
|
||||
assert!(r1.len() == 0);
|
||||
|
||||
let cr = server.create();
|
||||
assert!(cr.is_ok());
|
||||
|
||||
let r2 = server.search().unwrap();
|
||||
assert!(r2.len() == 1);
|
||||
|
||||
future::ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,16 +57,27 @@ macro_rules! run_test {
|
|||
|
||||
#[test]
|
||||
fn test_schema() {
|
||||
run_test!(|log: actix::Addr<EventLog>, server| log.send(LogEvent {
|
||||
msg: String::from("Test log event")
|
||||
}));
|
||||
run_test!(
|
||||
|log: actix::Addr<EventLog>, server: actix::Addr<QueryServer>| log.send(LogEvent {
|
||||
msg: String::from("Test log event")
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn test_be_create_user() {
|
||||
run_test!(|log, be, server| {
|
||||
println!("It works");
|
||||
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(())
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue