
MessageTest.pudu
Pudu47 lines2.8 KB
1/** @Test.Message.Suite — shapes, tags, envelopes, and answers */2module PuduLangMediator.MessageTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMediator.Message as Message7import PuduLangMediator as Messaging8import PuduLangMediator.Utils.Erasure as Erasure91011fn main() -> Int {12 let info = Message.Info{name: "orders.get", shape: Message.Query, tags: ["audited"]}13 let outcomes: Erasure.Slot[Messaging.Outcome[Int, Str]] = Erasure.slot()14 let others: Erasure.Slot[Messaging.Outcome[Int, Str]] = Erasure.slot()15 let messages: Erasure.Slot[Str] = Erasure.slot()16 let good = Message.answered(&info, &outcomes, Ok(3))17 let bad = Message.answered(&info, &outcomes, Err(Messaging.Raised("no")))18 let lost = Message.undelivered(&info, Message.NoRoute("orders.get"))19 let foreign = Message.undelivered(&info, Message.WrongKind("orders.get"))20 let quiet = Message.unheard(&info)21 let sealed = Message.sealed(&info, &messages, "payload")22 let checks = Test.suite("Message", &[23 Test.equals("every shape is named", &[Message.Query, Message.Command, Message.Event, Message.Sequence].map(|shape: Message.Shape| Message.shapeName(&shape)), &[24 "query", "command", "event", "sequence"25 ]),26 Test.that("a carried tag is found", Message.hasTag(&info, "audited")),27 Test.not("a missing tag is not", Message.hasTag(&info, "cached")),28 Test.equals("a value answer reads back", &Message.read(&outcomes, &good), &Some(Ok(3))),29 Test.equals("a value answer is summarized", &(good.failed, good.summary), &(false, "Ok(3)")),30 Test.equals("a failed answer is marked", &(bad.failed, bad.summary), &(true, "The handler failed: \"no\"")),31 Test.equals("another kind's slot does not read an answer", &Message.read(&others, &good), &None),32 Test.equals("an unrouted envelope answers unhandled", &Message.read(&outcomes, &lost), &Some(Err(Messaging.Unhandled("orders.get")))),33 Test.equals("a misrouted envelope answers mismatched", &Message.read(&outcomes, &foreign), &Some(Err(Messaging.Mismatched("orders.get")))),34 Test.equals("an undelivered answer is failed and described", &(lost.failed, lost.summary), &(true, "No handler is registered for 'orders.get'.")),35 Test.equals("an unheard answer is quiet", &(quiet.failed, quiet.summary), &(false, "Ok(())")),36 Test.equals("an unheard answer holds no typed outcome", &Message.read(&outcomes, &quiet), &None),37 Test.equals("an envelope shows its message", &sealed.summary, &"\"payload\""),38 Test.equals("an envelope's message reads back through its slot", &Erasure.unpack(&messages, &sealed.packed), &Some("payload")),39 Test.equals("a fault's failure suits any error type", &Message.failureOf(&Message.NoRoute("x")), &Messaging.Unhandled("x"))40 ])41 let ran = Test.run(&checks)42 for failure in Test.failuresOf(&ran) {43 let _reported = Io.writeErrorLine(failure)44 }45 Test.report(&ran)46}47