Added records function to client.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2026-03-25 05:37:26 -04:00
parent d960d8fd03
commit 83821ee89b
2 changed files with 77 additions and 2 deletions

View File

@@ -155,6 +155,53 @@ impl MTTClient {
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
}
}
pub fn records<UA>(&self, request: UA) -> Result<Records, MTTError>
where
UA: Into<ClientAction>,
{
let req = request.into();
let doc_id = req.doc_name().clone();
let msg_id = MessageID::new();
let paths = [
Path::new(
Include::Just(msg_id.clone()),
Include::Just(doc_id.clone()),
Include::Just(Action::Records),
),
Path::new(
Include::Just(msg_id.clone()),
Include::All,
Include::Just(Action::Error),
),
];
for path in paths.iter() {
let reg_msg = Register::new(self.sender_id.clone(), RegMsg::AddRoute(path.clone()));
self.queue.send(Message::new(reg_msg));
let result = self.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(doc_id.clone()));
return Err(error);
}
_ => {}
},
_ => unreachable!("got {:?} should have been a registry message", action),
}
}
self.queue.send(Message::with_id(msg_id, req));
match self.rx.recv_timeout(TIMEOUT) {
Ok(data) => match data.get_action() {
MsgAction::Records(data) => Ok(data.clone()),
MsgAction::Error(err) => Err(err.clone()),
_ => unreachable!("should only receive records or errors"),
},
Err(_) => Err(MTTError::new(ErrorID::TimeOut)),
}
}
}
impl Drop for MTTClient {

View File

@@ -1,8 +1,12 @@
mod support;
use isolang::Language;
use morethantext::{
Action, DocDef, ErrorID, Field, Include, MTTError, MoreThanText, Name, Path, TestMoreThanText,
Action, Addition, DocDef, ErrorID, Field, FieldType, Include, MTTError, MoreThanText, Name,
Path, Query, TestMoreThanText,
};
use std::{collections::HashSet, sync::mpsc::RecvTimeoutError};
use support::setup_range;
use uuid::Uuid;
fn doc_name() -> Name {
@@ -139,7 +143,31 @@ fn can_error_on_create_document() {
let mtt = MoreThanText::new();
let client = mtt.client();
client.create_document(docdef.clone()).unwrap();
let mut expected = MTTError::new(ErrorID::NameAlreadyExists);
let expected = MTTError::new(ErrorID::NameAlreadyExists);
let result = client.create_document(docdef).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
#[test]
fn can_perform_client_tasks() {
let count = 5;
let (test_env, test_doc) = setup_range(count.clone());
let qry = Query::new(test_doc.get_doc_name());
let client = test_env.get_morethantext().client();
let result = client.records(qry).unwrap();
assert_eq!(result.len(), count);
}
#[test]
fn can_error_on_client_tasks() {
let count = 5;
let (test_env, test_doc) = setup_range(count.clone());
let mut add = Addition::new(test_doc.get_doc_name());
add.add_field(test_doc.get_field_name(0), "pie");
let mut expected = MTTError::new(ErrorID::FieldTypeExpected(FieldType::Integer));
expected.add_parent(ErrorID::Field(test_doc.get_field_name(0).into()));
expected.add_parent(ErrorID::Document(test_doc.get_doc_name().into()));
let client = test_env.get_morethantext().client();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}