Moved create document testing into library tests.
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
8c73798f95
commit
f334bfa9f1
@ -61,111 +61,6 @@ impl CreateDoc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod createdocs {
|
|
||||||
use super::*;
|
|
||||||
use crate::{name::Name, support_tests::TIMEOUT};
|
|
||||||
|
|
||||||
struct TestCreateDoc {
|
|
||||||
queue: Queue,
|
|
||||||
rx: Receiver<Message>,
|
|
||||||
rx_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestCreateDoc {
|
|
||||||
fn new() -> Self {
|
|
||||||
let mut queue = Queue::new();
|
|
||||||
let (tx, rx) = channel();
|
|
||||||
let id = queue.add_sender(tx);
|
|
||||||
CreateDoc::start(queue.clone());
|
|
||||||
Self {
|
|
||||||
queue: queue,
|
|
||||||
rx: rx,
|
|
||||||
rx_id: id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_queue(&self) -> Queue {
|
|
||||||
self.queue.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_receiver(&self) -> &Receiver<Message> {
|
|
||||||
&self.rx
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_paths(&self, paths: Vec<Path>) {
|
|
||||||
for path in paths.iter() {
|
|
||||||
let regmsg = Register::new(self.rx_id.clone(), RegMsg::AddRoute(path.clone()));
|
|
||||||
self.queue.send(Message::new(regmsg));
|
|
||||||
self.rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_document_creation() {
|
|
||||||
let doc_creator = TestCreateDoc::new();
|
|
||||||
let paths = [
|
|
||||||
Path::new(Include::All, Include::All, Include::Just(Action::DocumentCreated)),
|
|
||||||
Path::new(Include::All, Include::All, Include::Just(Action::Records)),
|
|
||||||
]
|
|
||||||
.to_vec();
|
|
||||||
doc_creator.register_paths(paths);
|
|
||||||
let queue = doc_creator.get_queue();
|
|
||||||
let rx = doc_creator.get_receiver();
|
|
||||||
let name = Name::english("project");
|
|
||||||
let msg1 = Message::new(MsgAction::Create(DocDef::new(name.clone())));
|
|
||||||
queue.send(msg1.clone());
|
|
||||||
let result1 = rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
result1.get_message_id(),
|
|
||||||
msg1.get_message_id(),
|
|
||||||
"received {:?} from create message.",
|
|
||||||
rx
|
|
||||||
);
|
|
||||||
match result1.get_action() {
|
|
||||||
MsgAction::DocumentCreated => {}
|
|
||||||
_ => unreachable!("got {:?}: should have been a reply.", result1.get_action()),
|
|
||||||
}
|
|
||||||
let msg2 = Message::new(Query::new(name.clone()));
|
|
||||||
queue.send(msg2.clone());
|
|
||||||
let result2 = rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
assert_eq!(result2.get_message_id(), msg2.get_message_id());
|
|
||||||
match result2.get_action() {
|
|
||||||
MsgAction::Records(data) => assert_eq!(data.len(), 0),
|
|
||||||
_ => unreachable!("got {:?}: should have been a reply.", result1.get_action()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn does_duplicates_generate_error() {
|
|
||||||
let doc_creator = TestCreateDoc::new();
|
|
||||||
let paths = [Path::new(
|
|
||||||
Include::All,
|
|
||||||
Include::All,
|
|
||||||
Include::Just(Action::Error),
|
|
||||||
)]
|
|
||||||
.to_vec();
|
|
||||||
doc_creator.register_paths(paths);
|
|
||||||
let queue = doc_creator.get_queue();
|
|
||||||
let rx = doc_creator.get_receiver();
|
|
||||||
let name = Name::english("duplicate");
|
|
||||||
let msg1 = Message::new(MsgAction::Create(DocDef::new(name.clone())));
|
|
||||||
let msg2 = Message::new(MsgAction::Create(DocDef::new(name.clone())));
|
|
||||||
queue.send(msg1.clone());
|
|
||||||
queue.send(msg2.clone());
|
|
||||||
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
assert_eq!(result.get_message_id(), msg2.get_message_id());
|
|
||||||
match result.get_action() {
|
|
||||||
MsgAction::Error(err) => match err.error_id() {
|
|
||||||
ErrorID::NameAlreadyExists => {}
|
|
||||||
_ => unreachable!("got {:?}: should have been a duplicate name", err),
|
|
||||||
},
|
|
||||||
_ => unreachable!("got {:?}: should have been a reply.", result.get_action()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum IndexType {
|
pub enum IndexType {
|
||||||
Index,
|
Index,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use morethantext::{action::*, MoreThanText, TestMoreThanText};
|
use morethantext::{action::*, ErrorID, Name, MoreThanText, TestMoreThanText};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -7,4 +7,21 @@ fn is_document_created() {
|
|||||||
let doc_name = TestMoreThanText::random_name();
|
let doc_name = TestMoreThanText::random_name();
|
||||||
let docdef = DocDef::new(doc_name.clone());
|
let docdef = DocDef::new(doc_name.clone());
|
||||||
mtt.create_document(docdef).unwrap();
|
mtt.create_document(docdef).unwrap();
|
||||||
|
let qry = Query::new(doc_name);
|
||||||
|
let result = mtt.records(qry).unwrap();
|
||||||
|
assert_eq!(result.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn are_errors_produced_for_duplicate_names() {
|
||||||
|
let mut mtt = MoreThanText::new();
|
||||||
|
let docdef = DocDef::new(Name::english("duplicate"));
|
||||||
|
mtt.create_document(docdef.clone()).unwrap();
|
||||||
|
match mtt.create_document(docdef) {
|
||||||
|
Ok(_) => assert!(false, "should have failed"),
|
||||||
|
Err(err) => match err.error_id() {
|
||||||
|
ErrorID::NameAlreadyExists => {},
|
||||||
|
_ => unreachable!("got {:?}, should be name already exists", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user