Moved failed to find document into lib 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
5251689158
commit
97f9d24330
@ -1139,7 +1139,7 @@ mod document_files {
|
||||
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||
match result.get_action() {
|
||||
MsgAction::Error(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should have been document field not found.", err),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have been an error", result.get_action()),
|
||||
@ -1449,7 +1449,7 @@ mod document_files {
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Error(data) => match data.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should been field not found", data),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have been a error", action),
|
||||
@ -1761,7 +1761,7 @@ mod document_files {
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Error(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should have gotten an missing field", err),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have gotten an error", action),
|
||||
@ -2084,7 +2084,7 @@ mod document_files {
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Error(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should have gotten an missing field", err),
|
||||
},
|
||||
_ => unreachable!("got {:?}: should have gotten an error", action),
|
||||
|
||||
@ -408,7 +408,7 @@ mod docdefs {
|
||||
match docdef.get_field(&name) {
|
||||
Ok(_) => unreachable!("should return non existant field error"),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should have been document field not found", err),
|
||||
},
|
||||
}
|
||||
@ -456,7 +456,7 @@ mod docdefs {
|
||||
match docdef.set_default(&field_name, FieldType::Uuid) {
|
||||
Ok(_) => unreachable!("should be an error"),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?}: should have been field not found", err),
|
||||
},
|
||||
}
|
||||
|
||||
17
src/lib.rs
17
src/lib.rs
@ -116,14 +116,27 @@ impl MoreThanText {
|
||||
),
|
||||
Path::new(
|
||||
Include::Just(msg_id.clone()),
|
||||
Include::Just(doc_id.clone()),
|
||||
Include::All,
|
||||
Include::Just(Action::Error),
|
||||
),
|
||||
];
|
||||
for path in paths.iter() {
|
||||
let reg_msg = Register::new(sender_id.clone(), RegMsg::AddRoute(path.clone()));
|
||||
self.queue.send(Message::new(reg_msg));
|
||||
rx.recv().unwrap(); // Wait for completion.
|
||||
let result = rx.recv().unwrap();
|
||||
let action = result.get_action();
|
||||
match action {
|
||||
MsgAction::Register(status) => match status.get_msg() {
|
||||
RegMsg::Error(err) => {
|
||||
let mut error = err.clone();
|
||||
error.add_parent(ErrorID::Document(msg.doc_name().clone()));
|
||||
self.queue.remove_sender(&sender_id);
|
||||
return Err(error);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => unreachable!("got {:?} should have been a registry message", action),
|
||||
}
|
||||
}
|
||||
self.queue.send(msg);
|
||||
let output = match rx.recv_timeout(TIMEOUT) {
|
||||
|
||||
@ -33,21 +33,6 @@ impl Message {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn new<D, A>(doc_id: D, action: A) -> Self
|
||||
where
|
||||
D: Into<NameType>,
|
||||
A: Into<MsgAction>,
|
||||
{
|
||||
Self {
|
||||
msg_id: Uuid::new_v4(),
|
||||
document_id: doc_id.into(),
|
||||
action: action.into(),
|
||||
route: Route::default(),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn get_message_id(&self) -> &Uuid {
|
||||
&self.msg_id
|
||||
}
|
||||
@ -96,6 +81,12 @@ impl Message {
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageAction for Message {
|
||||
fn doc_name(&self) -> &NameType {
|
||||
self.get_action().doc_name()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod messages {
|
||||
use super::*;
|
||||
|
||||
@ -21,7 +21,7 @@ pub enum ErrorID {
|
||||
InvalidFieldName(Name),
|
||||
NameAlreadyExists,
|
||||
NameLanguageNotUnique,
|
||||
NameNotFound,
|
||||
NameNotFound(NameType),
|
||||
TimeOut,
|
||||
}
|
||||
|
||||
|
||||
13
src/name.rs
13
src/name.rs
@ -130,10 +130,11 @@ impl Names {
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
match name.into() {
|
||||
let name_type = name.into();
|
||||
match name_type.clone() {
|
||||
NameType::Name(data) => match self.names.get(&data) {
|
||||
Some(id) => Ok(id.clone()),
|
||||
None => Err(MTTError::new(ErrorID::NameNotFound)),
|
||||
None => Err(MTTError::new(ErrorID::NameNotFound(name_type))),
|
||||
},
|
||||
NameType::ID(data) => {
|
||||
if self.ids.contains_key(&data) {
|
||||
@ -142,7 +143,7 @@ impl Names {
|
||||
if data == Uuid::nil() {
|
||||
Ok(data)
|
||||
} else {
|
||||
Err(MTTError::new(ErrorID::NameNotFound))
|
||||
Err(MTTError::new(ErrorID::NameNotFound(name_type)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,11 +232,12 @@ mod names {
|
||||
#[test]
|
||||
fn errors_on_bad_name() {
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let expected: NameType = name.clone().into();
|
||||
let names = Names::new();
|
||||
match names.get_id(name.clone()) {
|
||||
Ok(data) => unreachable!("got {:?}, should have been missing error", data),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(data) => assert_eq!(data, &expected),
|
||||
_ => unreachable!("got {:?}, should have been missing error", err),
|
||||
},
|
||||
}
|
||||
@ -244,11 +246,12 @@ mod names {
|
||||
#[test]
|
||||
fn errors_on_bad_id() {
|
||||
let id = Uuid::new_v4();
|
||||
let expected: NameType = id.clone().into();
|
||||
let names = Names::new();
|
||||
match names.get_id(id.clone()) {
|
||||
Ok(data) => unreachable!("got {:?}, should have been missing error", data),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(data) => assert_eq!(data, &expected),
|
||||
_ => unreachable!("got {:?}, should have been missing error", err),
|
||||
},
|
||||
}
|
||||
|
||||
@ -314,7 +314,7 @@ mod queues {
|
||||
let regmsg = data.get_msg();
|
||||
match data.get_msg() {
|
||||
RegMsg::Error(err) => match err.get_error_ids().back().unwrap() {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!("got {:?} should have been missing name", err),
|
||||
},
|
||||
_ => unreachable!("got {:?} should have been error", regmsg),
|
||||
|
||||
@ -2,7 +2,7 @@ mod support;
|
||||
|
||||
use morethantext::{
|
||||
action::{Addition, DocDef, Field, FieldType, Query},
|
||||
ErrorID, MoreThanText, Name,
|
||||
ErrorID, MTTError, MoreThanText, Name,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use support::random_name;
|
||||
@ -43,13 +43,18 @@ fn can_new_documents_be_added() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "need to alter error"]
|
||||
fn does_it_error_on_a_bad_field_name() {
|
||||
fn does_it_error_on_a_bad_document_name() {
|
||||
let mut mtt = MoreThanText::new();
|
||||
let doc_name = Name::english("empty");
|
||||
mtt.create_document(DocDef::new(doc_name.clone()));
|
||||
let mut add = Addition::new(doc_name.clone());
|
||||
add.add_field(Name::english("missing"), "stuff");
|
||||
let mut expected = MTTError::new(ErrorID::NameNotFound(doc_name.clone().into()));
|
||||
expected.add_parent(ErrorID::Document(doc_name.clone().into()));
|
||||
let add = Addition::new(doc_name.clone());
|
||||
let result = mtt.records(add).unwrap_err();
|
||||
assert_eq!(result.to_string(), expected.to_string());
|
||||
|
||||
|
||||
|
||||
/*
|
||||
let result = mtt
|
||||
.records(add)
|
||||
.unwrap_err()
|
||||
@ -58,10 +63,11 @@ fn does_it_error_on_a_bad_field_name() {
|
||||
.unwrap()
|
||||
.clone();
|
||||
match result {
|
||||
ErrorID::NameNotFound => {}
|
||||
ErrorID::NameNotFound(_) => {}
|
||||
_ => unreachable!(
|
||||
"got {:?}: should have been document field not found.",
|
||||
result
|
||||
),
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user