Skip to content

Commit c06f929

Browse files
committed
Auto merge of #3130 - Turbo87:test-logging, r=pietroalbini
tests: Initialize env_logger in `TestApp::init()` This allows us to use e.g. `debug!()` in test utilities and run `cargo test` with `RUST_LOG=debug`. This PR also adds `debug!()` calls to our HTTP proxy replay code, to make it easier to see what requests have been intercepted by the proxy. r? `@pietroalbini`
2 parents 92df8ae + a4658bc commit c06f929

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/tests/all.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extern crate diesel;
77
#[macro_use]
88
extern crate lazy_static;
99
#[macro_use]
10+
extern crate log;
11+
#[macro_use]
1012
extern crate serde;
1113
#[macro_use]
1214
extern crate serde_json;

src/tests/record.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ fn replay_http(
292292
) -> impl Future<Output = Result<Response<Body>, Error>> + Send {
293293
static IGNORED_HEADERS: &[&str] = &["authorization", "date", "cache-control"];
294294

295+
debug!("<- {:?}", req);
295296
assert_eq!(req.uri().to_string(), exchange.request.uri);
296297
assert_eq!(req.method().to_string(), exchange.request.method);
297298
assert_ok!(writeln!(
@@ -337,6 +338,7 @@ fn replay_http(
337338
let status = StatusCode::from_u16(exchange.response.status).unwrap();
338339
let response = builder.status(status).body(body.into()).unwrap();
339340

341+
debug!("-> {:?}", response);
340342
Ok(response)
341343
}
342344
}

src/tests/util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ use url::Url;
4747

4848
pub use conduit::{header, StatusCode};
4949

50+
pub fn init_logger() {
51+
let _ = env_logger::builder()
52+
.format_timestamp(None)
53+
.is_test(true)
54+
.try_init();
55+
}
56+
5057
struct TestAppInner {
5158
app: Arc<App>,
5259
// The bomb (if created) needs to be held in scope until the end of the test.
@@ -92,6 +99,8 @@ pub struct TestApp(Rc<TestAppInner>);
9299
impl TestApp {
93100
/// Initialize an application with an `Uploader` that panics
94101
pub fn init() -> TestAppBuilder {
102+
init_logger();
103+
95104
TestAppBuilder {
96105
config: crate::simple_config(),
97106
proxy: None,

0 commit comments

Comments
 (0)