with_raw
with_raw checks the bytes of the latest payload published to the destination.
The assertion compares the payload byte for byte, with no codec involved.
It pins the wire form: field names, field order and the codec's formatting.
It also reads payloads no codec produced, such as a type that serializes itself.
It panics when nothing was published or the bytes differ.
with checks the latest payload as a value, and messages returns every payload.
Example
- Macros
- Manual
#[tokio::test]
async fn the_receipt_keeps_its_wire_form() -> 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")
.with_raw(br#"{"order_id":7}"#);
Ok(())
}
#[tokio::test]
async fn the_receipt_keeps_its_wire_form() -> 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")
.with_raw(br#"{"order_id":7}"#);
Ok(())
}