Update only matches query.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
5bb7f1b108
commit
cda6cc1c8c
@ -2410,6 +2410,51 @@ mod document_files {
|
||||
_ => unreachable!("got {:?}: should have gotten a reply", action),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changes_only_the_queried() {
|
||||
let (mut docdef, doc_name) =
|
||||
create_docdef([FieldType::Uuid, FieldType::StaticString].to_vec());
|
||||
let (mut queue, rx) = test_doc(doc_name.as_str(), docdef, standard_routes());
|
||||
let id1 = Uuid::new_v4();
|
||||
let id2 = Uuid::new_v4();
|
||||
let old = "old";
|
||||
let new = "new";
|
||||
for id in [id1.clone(), id2.clone()].into_iter() {
|
||||
let mut addition = Addition::new();
|
||||
addition.add_field("field0".to_string(), id);
|
||||
addition.add_field("field1".to_string(), old);
|
||||
let msg = Message::new(doc_name.clone(), addition);
|
||||
queue.send(msg).unwrap();
|
||||
rx.recv_timeout(TIMEOUT).unwrap();
|
||||
}
|
||||
let mut update = Update::new();
|
||||
update
|
||||
.get_query_mut()
|
||||
.add_specifier("field0".to_string(), Operand::Equal, id1.clone());
|
||||
update.get_values_mut().add_field("field1".to_string(), new);
|
||||
let msg = Message::new(doc_name.clone(), update);
|
||||
queue.send(msg).unwrap();
|
||||
rx.recv_timeout(TIMEOUT).unwrap();
|
||||
let mut query = Query::new();
|
||||
query.add_specifier("field0".to_string(), Operand::Equal, id2.clone());
|
||||
let msg = Message::new(doc_name, query);
|
||||
queue.send(msg).unwrap();
|
||||
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Reply(docs) => {
|
||||
assert_eq!(docs.len(), 1);
|
||||
let expected_id: Field = id2.into();
|
||||
let output: Field = old.into();
|
||||
for doc in docs.iter() {
|
||||
assert_eq!(doc.get_field("field0").unwrap(), &expected_id);
|
||||
assert_eq!(doc.get_field("field1").unwrap(), &output);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("got {:?}: should have gotten a reply", action),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user