Skip to main content

PublishedAssertions

Struct PublishedAssertions 

Source
pub struct PublishedAssertions<T> { /* private fields */ }
Expand description

Assertions over what was published to one channel, read from the broker’s publish log or from an Out slot’s view. The type parameter T is the expected payload type for with.

Implementations§

Source§

impl<T> PublishedAssertions<T>

Source

pub fn assert_called_once(self) -> Self

Asserts exactly one message was published to this channel.

§Panics

Panics if zero or more than one message was published.

Source

pub fn assert_called(self, times: usize) -> Self

Asserts exactly times messages were published to this channel.

§Panics

Panics if the published count differs from times.

Source

pub fn assert_not_called(self)

Asserts nothing was published to this channel.

§Panics

Panics if any message was published.

Source

pub fn messages(&self) -> &[RawMessage]

Every message published to this channel, in publish order, for custom inspection beyond the built-in assertions. Bind the assertions to a variable to borrow them: let pubs = tb.broker::<B>().published::<T>("x"); for m in pubs.messages() { .. }.

Source

pub fn decoded_as<U>(self) -> PublishedAssertions<U>

Re-types the expected payload, for assertion sources that do not name one up front (tb.out::<Slot>().decoded_as::<Reply>().with(&expected)).

Source

pub fn with_options<Options>(self, expected: &Options) -> Self
where Options: PartialEq + Debug + 'static,

Asserts the most recent publish carried exactly expected as the broker’s per-message options.

The options are what the broker’s builder steps set on that one publish (see PublishBuilder::options_mut); a publish no step touched carried none, which assert_options_default asserts. The harness records them with every publish the runtime makes (a reply, an Out slot publish, a retry copy), on the broker it went to, so a broker’s view and a slot view both read them.

§Panics

Panics if nothing was published, the harness cannot say which options the most recent publish carried (the test published it itself, a publisher the runtime did not pair made it, or another publish there has the same payload and either the order of the two is unknown or the harness never saw that one), it carried none, the broker’s options type is not Options, or the value differs from expected.

Source

pub fn assert_options_default(self) -> Self

Asserts the most recent publish carried no per-message options: no builder step ran on it, and the publish policy’s own settings applied.

Recorded for every publish the runtime makes, like with_options.

§Panics

Panics if nothing was published, the harness cannot say which options the most recent publish carried (see with_options), or a step did set options on the publish.

Source

pub fn with_raw(self, bytes: &[u8]) -> Self

Asserts the most recent published payload equals bytes.

§Panics

Panics if nothing was published, or the raw payload differs.

Source

pub fn with_header(self, name: &str, value: impl AsRef<[u8]>) -> Self

Asserts the most recent published message carries the header name with value.

What a publish transform or an app-wide publish_layer put on the message is read here: the assertion sees the message as it left, so a stamp added on the way out shows up on the reply channel and on tb.out::<Marker>() alike.

§Panics

Panics if nothing was published, the header is absent, or its value differs.

Source§

impl<T> PublishedAssertions<T>

Source

pub fn with(self, expected: &T) -> Self

Asserts the most recent published payload decodes (with DefaultCodec) to expected. If the publisher uses a different codec, use with_codec.

§Panics

Panics if nothing was published, the payload fails to decode, or it differs from expected.

Source§

impl<T> PublishedAssertions<T>

Source

pub fn with_codec<C: Codec>(self, codec: &C, expected: &T) -> Self

Like with, but decodes the published payload with codec - use it when the publisher was built with a non-default codec.

§Panics

Panics if nothing was published, the payload fails to decode, or it differs from expected.

Source§

impl<T: DeserializeOwned> PublishedAssertions<T>

Source

pub fn decoded(&self) -> Vec<T>

Decodes every message published to this channel (with DefaultCodec), in publish order, for custom inspection. Use decoded_with for a non-default codec.

§Panics

Panics if any published payload fails to decode as T.

Source§

impl<T: DeserializeOwned> PublishedAssertions<T>

Source

pub fn decoded_with<C: Codec>(&self, codec: &C) -> Vec<T>

Like decoded, but decodes with codec - use it when the publisher was built with a non-default codec.

§Panics

Panics if any published payload fails to decode as T.

Trait Implementations§

Source§

impl<T: Debug> Debug for PublishedAssertions<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for PublishedAssertions<T>

§

impl<T> !UnwindSafe for PublishedAssertions<T>

§

impl<T> Freeze for PublishedAssertions<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> Send for PublishedAssertions<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for PublishedAssertions<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for PublishedAssertions<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for PublishedAssertions<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PublishedThrough<DefaultSlot> for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more