Allows your integration tests to run your application under a separate process and assert on tokio-tracing events.
It is a little opinionated and by default will fail the test when a tracing warning or error occurs.
However a specific warning or error can be allowed on a per test basis.
Example usage for an imaginary database project named cooldb:
use tokio_bin_process::event::Level;
use tokio_bin_process::BinProcess;
use tokio_bin_process::event_matcher::EventMatcher;
use std::time::Duration;
async fn cooldb_process() -> BinProcess {
let mut process = BinProcess::start_with_args(
"cooldb", "cooldb", &[
"--foo", "bar",
"--log-format", "json"
],
)
.await;
tokio::time::timeout(
Duration::from_secs(30),
process.wait_for(
&EventMatcher::new()
.with_level(Level::Info)
.with_target("cooldb")
.with_message("accepting inbound connections"),
),
)
.await
.unwrap();
process
}
#[tokio::test]
async fn test_some_functionality() {
let cooldb = cooldb_process().await;
perform_test();
cooldb
.shutdown_and_then_consume_events(&[
EventMatcher::new()
.with_level(Level::Warn)
.with_target("cooldb::internal")
.with_message("The user did something silly that we want to warn about but is actually expected in this test case")
])
.await;
}