with
with checks that the latest payload published to the destination decodes to a value; with_codec names the codec.
with(&value) decodes the latest payload with the default codec and compares it with value.
It exists when a codec feature is enabled.
with_codec(&codec, &value) decodes with the codec the mount site named.
Both panic when nothing was published, when the payload does not decode, or when the value differs.
Both return the record, so further assertions chain.
decoded returns every payload, not only the latest, and with_raw checks the latest payload as bytes.
A subscriber's with checks the value a handler received.
Example
- Macros
- Manual
#[tokio::test]
async fn the_receipt_names_the_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for queue in ["orders", "legacy-orders"] {
broker
.message(&Order { id: 7, seats: 1 })
.to(queue)
.publish()
.await?;
}
broker
.published::<Receipt>("receipts")
.with(&Receipt { order_id: 7 });
broker
.published::<Invoice>("invoices")
.with_codec(&Versioned, &Invoice { order_id: 7 });
Ok(())
}
#[tokio::test]
async fn the_receipt_names_the_order() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
for queue in ["orders", "legacy-orders"] {
broker
.message(&Order { id: 7, seats: 1 })
.to(queue)
.publish()
.await?;
}
broker
.published::<Receipt>("receipts")
.with(&Receipt { order_id: 7 });
broker
.published::<Invoice>("invoices")
.with_codec(&Versioned, &Invoice { order_id: 7 });
Ok(())
}