Skip to content

Commit 268402c

Browse files
committed
chore(tests): Improve logging in smoke tests
Workaround until cucumber-rs/cucumber#353 gets fixed.
1 parent 8e2d8f1 commit 268402c

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

CONTRIBUTING.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ This has the added benefit of updating the version of Rust used to run the tests
5454
task smoke-test
5555
```
5656

57-
As explained in [ADR: Write tests with the Gherkin syntax](./ADRs/2024-01-11-a-write-tests-in-gherkin.md), we are using Gherkin and Cucumber to run the tests. Therefore, you won't be able to filter tests using `cargo test`. To do so, add a `@testing` tag to a `Feature`, `Rule` or `Scenario` (non-exhaustive) and then use `task smoke-test -- --tags '@testing'` to run only matching `Scenario`s.
57+
As explained in [ADR: Write tests with the Gherkin syntax](./ADRs/2024-01-11-a-write-tests-in-gherkin.md), we are using Gherkin and Cucumber to run the tests. Therefore, you won't be able to filter tests using `cargo test`. To do so, add a `@debug` tag to a `Feature`, `Rule` or `Scenario` (non-exhaustive) and then use `task smoke-test -- --tags '@debug'` to run only matching `Scenario`s.
58+
59+
> [!TIP]
60+
> You will get more logs if you use `@debug`. Also, `@debug` can be used without manually
61+
> putting it in a feature file, like so:
62+
> `task smoke-test -- --tags '@dns-record-checks or @debug'`.
5863
5964
### Integration testing
6065

crates/rest-api/tests/behavior.rs

+39-11
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,70 @@ mod prelude;
99

1010
use cucumber::World as _;
1111
use tracing_subscriber::{
12-
filter::{self, LevelFilter},
13-
fmt::format::{self, Format},
14-
layer::{Layer, SubscriberExt as _},
12+
filter::{self, FilterExt, FilterFn, LevelFilter},
13+
fmt::format::{self, FmtSpan, Format},
14+
layer::SubscriberExt as _,
15+
Layer,
1516
};
1617

1718
use crate::{prelude::*, test_world::TestWorld};
1819

1920
#[tokio::main]
2021
async fn main() {
22+
fn default_format<F, T>(format: Format<F, T>) -> Format<F, ()> {
23+
format
24+
.without_time()
25+
.with_ansi(true)
26+
.with_source_location(false)
27+
.with_target(true)
28+
}
29+
#[allow(unused)]
30+
fn normal<F, T>(format: Format<F, T>) -> Format<F, ()> {
31+
default_format(format)
32+
}
33+
#[allow(unused)]
34+
fn compact<F, T>(format: Format<F, T>) -> Format<format::Compact, ()> {
35+
default_format(format.compact())
36+
}
37+
let map_format = normal;
38+
2139
TestWorld::cucumber()
2240
// .init_tracing()
2341
.configure_and_init_tracing(
2442
format::DefaultFields::new(),
25-
Format::default(),
43+
map_format(Format::default()),
2644
|fmt_layer| {
2745
let targets = vec![
2846
("sea_orm_migration", LevelFilter::WARN),
47+
("sea_orm", LevelFilter::INFO),
2948
("sqlx::query", LevelFilter::ERROR),
3049
("globset", LevelFilter::WARN),
50+
("cucumber::tracing", LevelFilter::OFF),
3151
];
3252

3353
let args = std::env::args().collect::<Vec<_>>();
34-
let running_few_scenarios = args.contains(&"@testing".to_owned());
35-
let debug = args.contains(&"@debug".to_owned());
54+
let debug = args.iter().any(|s| s.contains("@debug"));
3655

37-
let default_level = if running_few_scenarios || debug {
56+
let default_level = if debug {
3857
LevelFilter::TRACE
3958
} else {
4059
LevelFilter::WARN
4160
};
4261

62+
let targets_layer = filter::Targets::new()
63+
.with_default(default_level)
64+
.with_targets(targets);
65+
let span_filter =
66+
FilterFn::new(|metadata| metadata.is_span() || !metadata.fields().is_empty());
67+
let event_span_layer = tracing_subscriber::fmt::layer()
68+
.map_event_format(map_format)
69+
.with_span_events(FmtSpan::CLOSE)
70+
.with_filter(span_filter.clone());
71+
4372
tracing_subscriber::registry().with(
44-
filter::Targets::new()
45-
.with_default(default_level)
46-
.with_targets(targets)
47-
.and_then(fmt_layer),
73+
targets_layer
74+
.and_then(event_span_layer)
75+
.and_then(fmt_layer.with_filter(span_filter.not())),
4876
)
4977
},
5078
)

0 commit comments

Comments
 (0)