Got backend using errors.

This commit is contained in:
2025-04-25 14:02:40 -04:00
parent cb9bac9d8a
commit 55ffa538e8
4 changed files with 166 additions and 14 deletions

View File

@ -31,11 +31,18 @@ impl Document {
fn listen(&mut self) {
loop {
let msg = self.rx.recv().unwrap();
let mut reply = msg.reply(MsgType::Document);
if msg.get_data("name").is_some() {
reply = msg.reply(MsgType::Error);
reply.add_data("error_type", ErrorType::DocumentNotFound);
}
let mut reply = match msg.get_data("name") {
Some(name) => {
if name.to_string() == "root" {
msg.reply(MsgType::Document)
} else {
let mut output = msg.reply(MsgType::Error);
output.add_data("error_type", ErrorType::DocumentNotFound);
output
}
},
None => msg.reply(MsgType::Document),
};
reply.add_data("doc", "Something goes hwew");
self.queue.send(reply).unwrap();
}
@ -95,4 +102,18 @@ pub mod documents {
None => unreachable!("should contain error type"),
}
}
#[test]
fn root_always_exists() {
let (queue, rx) = setup_document();
let name = format!("name-{}", Uuid::new_v4());
let mut msg = Message::new(MsgType::DocumentRequest);
msg.add_data("name", "root");
queue.send(msg);
let reply = rx.recv().unwrap();
match reply.get_msg_type() {
MsgType::Document => {},
_ => unreachable!("Got '{:?}': should have been a document", reply.get_msg_type()),
}
}
}