Skip to main content

with_value

with_value(&value) checks the value the latest delivery lent its handler, on a broker whose deliveries already hold one.

Some brokers decode a delivery in their client and lend the handler that value, such as a database row; the delivery implements Carries<T>. That value never was bytes, so with has nothing to decode; the harness keeps a clone of the lent value instead. The value type needs Clone, PartialEq and Debug. It panics when the latest delivery lent no T: the handler takes another type, or the delivery carried nothing. The row subscription here stands in for such a broker crate: it reads id:name payloads of the in-memory broker as rows (examples/support/carried_rows.rs). received_values returns every lent value, not only the latest.

Example​

#[tokio::test]
async fn the_handler_got_the_row() -> Result<(), Box<dyn Error>> {
let tb = TestApp::start(app()).await?;
let broker = tb.broker::<MemoryBroker>();
broker
.message(&Wire(b"7:alice".to_vec()))
.to("users")
.publish()
.await?;

broker
.subscriber("users")
.assert_called_once()
.with_value(&Row::new(7, "alice"))
.settled(HandlerOutcome::ack());
Ok(())
}