Added additional testing for query.w
This commit is contained in:
parent
741ef41422
commit
692f2dceb7
116
src/message.rs
116
src/message.rs
@ -1161,14 +1161,9 @@ impl DocDef {
|
|||||||
None => Err(MTTError::DocumentFieldNotFound(name.to_string())),
|
None => Err(MTTError::DocumentFieldNotFound(name.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> IntoIterator for &'a DocDef {
|
fn iter(&self) -> impl Iterator<Item = (&String, &FieldSetting)> {
|
||||||
type Item = <&'a DocDefMap as IntoIterator>::Item;
|
self.fields.iter()
|
||||||
type IntoIter = <&'a DocDefMap as IntoIterator>::IntoIter;
|
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
(&self.fields).into_iter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1372,14 +1367,9 @@ impl Document {
|
|||||||
fn get_field(&self, name: &str) -> Option<&Field> {
|
fn get_field(&self, name: &str) -> Option<&Field> {
|
||||||
self.data.get(name)
|
self.data.get(name)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> IntoIterator for &'a Document {
|
fn iter(&self) -> impl Iterator<Item = (&String, &Field)> {
|
||||||
type Item = <&'a DocumentMap as IntoIterator>::Item;
|
self.data.iter()
|
||||||
type IntoIter = <&'a DocumentMap as IntoIterator>::IntoIter;
|
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
(&self.data).into_iter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1494,7 +1484,7 @@ impl DocumentFile {
|
|||||||
fn add_document(&mut self, addition: &Addition) -> MsgAction {
|
fn add_document(&mut self, addition: &Addition) -> MsgAction {
|
||||||
let mut holder = Document::new();
|
let mut holder = Document::new();
|
||||||
let doc = addition.get_document();
|
let doc = addition.get_document();
|
||||||
for (key, value) in doc.into_iter() {
|
for (key, value) in doc.iter() {
|
||||||
match self.docdef.get_field(&key) {
|
match self.docdef.get_field(&key) {
|
||||||
Err(err) => return err.into(),
|
Err(err) => return err.into(),
|
||||||
Ok(field_info) => {
|
Ok(field_info) => {
|
||||||
@ -1510,7 +1500,7 @@ impl DocumentFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (key, _) in self.docdef.into_iter() {
|
for (key, _) in self.docdef.iter() {
|
||||||
match holder.get_field(key) {
|
match holder.get_field(key) {
|
||||||
Some(_) => {}
|
Some(_) => {}
|
||||||
None => return MTTError::DocumentFieldMissing(key.clone()).into(),
|
None => return MTTError::DocumentFieldMissing(key.clone()).into(),
|
||||||
@ -1858,9 +1848,103 @@ mod document_files {
|
|||||||
queue.send(msg).unwrap();
|
queue.send(msg).unwrap();
|
||||||
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
let action = result.get_action();
|
let action = result.get_action();
|
||||||
|
let field0: Field = field0.into();
|
||||||
|
let field1: Field = field1.into();
|
||||||
match action {
|
match action {
|
||||||
MsgAction::Reply(data) => {
|
MsgAction::Reply(data) => {
|
||||||
assert_eq!(data.len(), 1, "should return one entry");
|
assert_eq!(data.len(), 1, "should return one entry");
|
||||||
|
for doc in data.iter() {
|
||||||
|
assert_eq!(doc.get_field("field0").unwrap(), &field0);
|
||||||
|
assert_eq!(doc.get_field("field1").unwrap(), &field1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => unreachable!("got {:?}: should have been a reply", action),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gets_all_documents_in_query() {
|
||||||
|
let doc_name = "multiple";
|
||||||
|
let count = 4;
|
||||||
|
let input = Uuid::new_v4();
|
||||||
|
let (queue, rx) = test_doc(
|
||||||
|
doc_name,
|
||||||
|
create_docdef([FieldType::Uuid].to_vec()),
|
||||||
|
standard_routes(),
|
||||||
|
);
|
||||||
|
for _ in 0..3 {
|
||||||
|
let mut addition = Addition::new();
|
||||||
|
addition.add_field("field0".to_string(), Uuid::new_v4());
|
||||||
|
let msg = Message::new(doc_name, addition);
|
||||||
|
queue.send(msg).unwrap();
|
||||||
|
rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
|
}
|
||||||
|
for _ in 0..count {
|
||||||
|
let mut addition = Addition::new();
|
||||||
|
addition.add_field("field0".to_string(), input.clone());
|
||||||
|
let msg = Message::new(doc_name, addition);
|
||||||
|
queue.send(msg).unwrap();
|
||||||
|
rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
|
}
|
||||||
|
let mut query = Query::new();
|
||||||
|
query.add_specifier("field0".to_string(), Operand::Equal, input.clone());
|
||||||
|
let msg = Message::new(doc_name, query);
|
||||||
|
queue.send(msg).unwrap();
|
||||||
|
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
|
let action = result.get_action();
|
||||||
|
let input: Field = input.into();
|
||||||
|
match action {
|
||||||
|
MsgAction::Reply(data) => {
|
||||||
|
assert_eq!(data.len(), count, "should return {} entries", count);
|
||||||
|
for doc in data.iter() {
|
||||||
|
assert_eq!(doc.get_field("field0").unwrap(), &input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => unreachable!("got {:?}: should have been a reply", action),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn query_should_work_with_multiple_fields() {
|
||||||
|
let doc_name = "onlyone";
|
||||||
|
let (queue, rx) = test_doc(
|
||||||
|
doc_name,
|
||||||
|
create_docdef([FieldType::Uuid, FieldType::Uuid].to_vec()),
|
||||||
|
standard_routes(),
|
||||||
|
);
|
||||||
|
let field0 = Uuid::new_v4();
|
||||||
|
let field1 = Uuid::new_v4();
|
||||||
|
let input = [
|
||||||
|
[Uuid::new_v4(), Uuid::new_v4()],
|
||||||
|
[field0.clone(), field1.clone()],
|
||||||
|
[field1.clone(), field0.clone()],
|
||||||
|
[field0.clone(), Uuid::new_v4()],
|
||||||
|
[Uuid::new_v4(), field1.clone()],
|
||||||
|
];
|
||||||
|
for combo in input.iter() {
|
||||||
|
let mut addition = Addition::new();
|
||||||
|
addition.add_field("field0".to_string(), combo[0].clone());
|
||||||
|
addition.add_field("field1".to_string(), combo[1].clone());
|
||||||
|
let msg = Message::new(doc_name, addition);
|
||||||
|
queue.send(msg).unwrap();
|
||||||
|
rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
|
}
|
||||||
|
let mut query = Query::new();
|
||||||
|
query.add_specifier("field0".to_string(), Operand::Equal, field0.clone());
|
||||||
|
query.add_specifier("field1".to_string(), Operand::Equal, field1.clone());
|
||||||
|
let msg = Message::new(doc_name, query);
|
||||||
|
queue.send(msg).unwrap();
|
||||||
|
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
|
let action = result.get_action();
|
||||||
|
let field0: Field = field0.into();
|
||||||
|
let field1: Field = field1.into();
|
||||||
|
match action {
|
||||||
|
MsgAction::Reply(data) => {
|
||||||
|
assert_eq!(data.len(), 1, "should return one entry");
|
||||||
|
for doc in data.iter() {
|
||||||
|
assert_eq!(doc.get_field("field0").unwrap(), &field0);
|
||||||
|
assert_eq!(doc.get_field("field1").unwrap(), &field1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("got {:?}: should have been a reply", action),
|
_ => unreachable!("got {:?}: should have been a reply", action),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user