pub fn field<K>(name: K) -> ExpectedFieldExpand description
Construct a new ExpectedField.
For details on how to set the value of the expected field and
how to expect multiple fields, see the field module and the
ExpectedField and ExpectedFields structs.
span, see the span module and the ExpectedSpan and
NewSpan structs.
§Examples
use tracing_mock::{collector, expect};
let event = expect::event()
.with_fields(expect::field("field.name").with_value(&"field_value"));
let (collector, handle) = collector::mock()
.event(event)
.run_with_handle();
tracing::collect::with_default(collector, || {
tracing::info!(field.name = "field_value");
});
handle.assert_finished();A different field value will cause the test to fail:
ⓘ
use tracing_mock::{collector, expect};
let event = expect::event()
.with_fields(expect::field("field.name").with_value(&"field_value"));
let (collector, handle) = collector::mock()
.event(event)
.run_with_handle();
tracing::collect::with_default(collector, || {
tracing::info!(field.name = "different_field_value");
});
handle.assert_finished();