Skip to content

tests: Initialize env_logger in TestApp::init() #3130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extern crate diesel;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate serde_json;
Expand Down
2 changes: 2 additions & 0 deletions src/tests/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ fn replay_http(
) -> impl Future<Output = Result<Response<Body>, Error>> + Send {
static IGNORED_HEADERS: &[&str] = &["authorization", "date", "cache-control"];

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

debug!("-> {:?}", response);
Ok(response)
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ use url::Url;

pub use conduit::{header, StatusCode};

pub fn init_logger() {
let _ = env_logger::builder()
.format_timestamp(None)
.is_test(true)
.try_init();
}

struct TestAppInner {
app: Arc<App>,
// The bomb (if created) needs to be held in scope until the end of the test.
Expand Down Expand Up @@ -92,6 +99,8 @@ pub struct TestApp(Rc<TestAppInner>);
impl TestApp {
/// Initialize an application with an `Uploader` that panics
pub fn init() -> TestAppBuilder {
init_logger();

TestAppBuilder {
config: crate::simple_config(),
proxy: None,
Expand Down