Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

PropagationTest.pudu

Pudu32 lines1.6 KB

GitHub ↗
1/** @Test.Handlers.Propagation.Suite — headers of the operation in progress copied onto requests */2module PuduLangHttpClient.Handlers.PropagationTest34import Std.Concurrent.Cancel as Cancel5import Std.Http as Http6import Std.Io as Io7import Std.Test as Test8import PuduLangHttpClient.Handler as Handler9import PuduLangHttpClient.Handlers.Propagation as Propagation10import PuduLangHttpClient.Request as Request11import PuduLangHttpClient.Stub as Stub1213/// Runs the suite.14fn main() -> Int {15  let stub = Stub.create()16  Stub.respond(&stub, Http.Get, "/", 200, "")17  let incoming = || [("X-Correlation-Id", "c-1"), ("traceparent", "00-a-b-01"), ("x-tenant", "acme"), ("x-tenant", "beta")]18  let send = Handler.compose(&[Propagation.handler(&["x-correlation-id", "x-tenant"], incoming), Propagation.renaming(&[("traceparent", "x-parent"), ("missing", "x-missing")], incoming)], Stub.send(&stub))19  let _plain = send(Request.get("http://a/"), Cancel.token())20  let _own = send(Request.get("http://a/").withHeader("X-Tenant", "mine"), Cancel.token())21  let received = Stub.received(&stub)22  let checks = Test.suite("Handlers.Propagation", &[23      Test.equals("named headers are copied with every value, and renamed ones under their new name", &received[0].headers, &[("x-correlation-id", "c-1"), ("x-tenant", "acme"), ("x-tenant", "beta"), ("x-parent", "00-a-b-01")]),24      Test.equals("a header the request already carries is left alone", &received[1].headers, &[("X-Tenant", "mine"), ("x-correlation-id", "c-1"), ("x-parent", "00-a-b-01")])25    ])26  let ran = Test.run(&checks)27  for failure in Test.failuresOf(&ran) {28    let _reported = Io.writeErrorLine(failure)29  }30  Test.report(&ran)31}32