跳到主要内容
本页尚未翻译

下面显示的是英文原文。

with_header

with_header checks one header of the latest message published to the destination, such as one a transform or a publish layer added.

The record holds the message as it left the publish pipeline, so every header a transform or a publish layer added is there. The example stamps one header with a PublishTransform on the reply and one with a PublishLayer added app-wide by publish_layer. The header name is matched without regard to case; the value is compared as bytes, so a &str and a &[u8] both work. The assertion panics when nothing was published, when the header is absent, or when its value differs. messages gives the headers of every message.

Example​

#[tokio::test]
async fn the_receipt_left_stamped() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7, seats: 1 })
.to("orders")
.publish()
.await?;

broker
.published::<Receipt>("receipts")
.assert_called_once()
.with_header("x-schema", "2")
.with_header("x-service", "orders");
Ok(())
}