Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mediator

In-process messaging for Pudu: requests, notifications, streams, pipeline behaviors, processors, and exception handling

0.1.0Apache-2.01

InstallClose

RequestTest.pudu

Pudu40 lines2.3 KB

GitHub ↗
1/** @Test.Request.Suite — request kinds, tags, routes, envelopes, and answers */2module PuduLangMediator.RequestTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMediator.Message as Message7import PuduLangMediator as Messaging8import PuduLangMediator.Request as Request9import PuduLangMediator.Utils.Erasure as Erasure1011/// Runs the suite.12fn main() -> Int {13  let lookup: Request.Kind[Int, Str, Str] = Request.kind("users.get")14  let rename: Request.Kind[Str, (), Str] = Request.command("users.rename")15  let audited = Request.tagged(&Request.tagged(&lookup, ["audited"]), ["cached"])16  let route: Request.Route[Int, Str, Str] = Request.route()17  let sealed = Request.envelope(&lookup, 42)18  let answered = Message.answered(&lookup.info, &lookup.outcomes, Ok("ada"))19  let twin: Request.Kind[Int, Str, Str] = Request.kind("users.get")20  let checks = Test.suite("Request", &[21      Test.equals("a kind answering a value is a query", &lookup.info, &Message.Info{name: "users.get", shape: Message.Query, tags: []}),22      Test.equals("a kind answering nothing is a command", &rename.info.shape, &Message.Command),23      Test.equals("tags accumulate in order", &audited.info.tags, &["audited", "cached"]),24      Test.equals("a tagged kind is the same kind", &Erasure.unpack(&audited.requests, &sealed.packed), &Some(42)),25      Test.equals("a fresh route is empty", &(route.handlers.length(), route.behaviors.length(), route.preProcessors.length(), route.postProcessors.length(), route.exceptionHandlers.length(), route.exceptionActions.length()), &(0, 0, 0, 0, 0, 0)),26      Test.equals("an envelope carries the kind and the request", &(sealed.info.name, sealed.summary), &("users.get", "42")),27      Test.equals("an envelope does not open for a twin kind", &Erasure.unpack(&twin.requests, &sealed.packed), &None),28      Test.equals("the kind reads its own answer", &Request.answerOf(&lookup, &answered), &Some(Ok("ada"))),29      Test.equals("a twin kind does not", &Request.answerOf(&twin, &answered), &None),30      Test.equals("an unrouted answer reads as unhandled", &Request.answerOf(&lookup, &Message.undelivered(&lookup.info, Message.NoRoute("users.get"))), &Some(31          Err(Messaging.Unhandled("users.get"))32        ))33    ])34  let ran = Test.run(&checks)35  for failure in Test.failuresOf(&ran) {36    let _reported = Io.writeErrorLine(failure)37  }38  Test.report(&ran)39}40