9个版本 (破坏性)
0.8.0 | 2024年5月4日 |
---|---|
0.7.0 | 2022年8月5日 |
0.6.0 | 2022年5月5日 |
0.5.0 | 2022年5月3日 |
0.1.1 | 2022年1月10日 |
#2011 in 过程宏
每月833次下载
用于 4 个Crates(通过 test-span)
9KB
104 行
test-span
用于在跟踪跨度上进行快照测试的宏和实用工具。
如何使用
有关功能和行为更全面的列表,请参阅测试
use test_span::prelude::*;
#[test_span]
fn a_test() {
do_something();
// test_span provides your with three functions:
let spans = get_spans();
let logs = get_logs();
// you can get both in one call
let (spans, logs) = get_telemetry();
// This plays well with insta snapshots:
insta::assert_json_snapshot!(logs);
insta::assert_json_snapshot!(spans);
}
// Test span plays well with async
#[test_span(tokio::test)]
// you can specify the span / log level
// you would like to track like this:
#[level(tracing::Level::INFO)]
async fn an_sync_test() {
do_something_async().await;
// You still get access to each function
let spans = get_spans();
let logs = get_logs();
let (spans, logs) = get_telemetry();
}
限制
跨线程创建跟踪跨度很难跟踪。但是,我们提供了一个日志转储以进行检查
#[test_span]
fn track_across_threads() {
std::thread::spawn(|| {
tracing::info!("only in get_all_logs!");
})
.join()
.unwrap();
let logs = get_logs();
// not in get_logs()
assert!(!logs.contains_message("only in get_all_logs!");
// get_all_logs takes a filter Level
let all_logs = test_span::get_all_logs(&tracing::Level::INFO);
assert!(all_logs.contains_message("only in get_all_logs!"));
}
贡献
更多详细信息请参阅贡献文档
许可
根据您的选择,在[Apache许可证2.0版本](LICENSE-APACHE)或[MIT许可证](LICENSE-MIT)下许可。除非您明确说明,否则您有意提交以供包含在此crate中的任何贡献,根据Apache-2.0许可证的定义,应按上述方式双重许可,而不添加任何附加条款或条件。
依赖关系
~260–710KB
~17K SLoC