Begin adding query server tests

This commit is contained in:
William Brown 2018-11-07 17:27:11 +10:00
parent a684b1095a
commit 58e45149d4
5 changed files with 92 additions and 21 deletions

View file

@ -35,6 +35,8 @@ impl BackendAuditEvent {
#[derive(Debug)] #[derive(Debug)]
struct IdEntry { struct IdEntry {
// FIXME: This should be u64, but sqlite uses i32 ...
// Should we use a bigint pk and just be done?
id: i32, id: i32,
data: String, data: String,
} }
@ -151,6 +153,12 @@ impl Backend {
// Alloc a vec for the entries. // Alloc a vec for the entries.
// FIXME: Make this actually a good size for the result set ... // FIXME: Make this actually a good size for the result set ...
// FIXME: Actually compute indexes here. // 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(); let mut raw_entries: Vec<String> = Vec::new();
{ {
// Actually do a search now! // Actually do a search now!

View file

@ -185,4 +185,3 @@ mod tests {
assert!(!e.pres("name")); assert!(!e.pres("name"));
} }
} }

View file

@ -43,25 +43,15 @@ impl Filter {
// Go through the filter components and check them in the entry. // Go through the filter components and check them in the entry.
// This is recursive!!!! // This is recursive!!!!
match self { match self {
Filter::Eq(_, _) => { Filter::Eq(_, _) => false,
false Filter::Sub(_, _) => false,
}
Filter::Sub(_, _) => {
false
}
Filter::Pres(attr) => { Filter::Pres(attr) => {
// Given attr, is is present in the entry? // Given attr, is is present in the entry?
e.pres(attr.as_str()) e.pres(attr.as_str())
} }
Filter::Or(_) => { Filter::Or(_) => false,
false Filter::And(_) => false,
} Filter::Not(_) => false,
Filter::And(_) => {
false
}
Filter::Not(_) => {
false
}
} }
} }
} }

View file

@ -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 ... // 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(())
});
}
}

View file

@ -57,16 +57,27 @@ macro_rules! run_test {
#[test] #[test]
fn test_schema() { fn test_schema() {
run_test!(|log: actix::Addr<EventLog>, server| log.send(LogEvent { run_test!(
|log: actix::Addr<EventLog>, server: actix::Addr<QueryServer>| log.send(LogEvent {
msg: String::from("Test log event") msg: String::from("Test log event")
})); })
);
} }
/* /*
#[test] #[test]
fn test_be_create_user() { fn test_be_create_user() {
run_test!(|log, be, server| { run_test!(|log, server: actix::Addr<QueryServer>| {
println!("It works"); 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(())
}); });
} }
*/ */