本页尚未翻译
下面显示的是英文原文。
with_raw
with_raw(bytes) checks the exact bytes of the latest handler call, before any decoding.
It compares the payload as the broker delivered it, so it pins the wire format: here the JSON the default codec wrote.
It reads the most recent call only, and that call must hold one delivery.
It is the check for a handler that reads bytes itself, where no codec has a value to compare.
with checks the same call decoded, and received_raw returns the bytes of every call.
Example
- Macros
- Manual
#[tokio::test]
async fn the_order_arrived_as_json() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
broker
.subscriber("orders")
.assert_called_once()
.with_raw(br#"{"id":7}"#);
Ok(())
}
#[tokio::test]
async fn the_order_arrived_as_json() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Order { id: 7 })
.to("orders")
.publish()
.await?;
broker
.subscriber("orders")
.assert_called_once()
.with_raw(br#"{"id":7}"#);
Ok(())
}