Skip to content

Commit

Permalink
test(logging): isolate tests by setting env temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
aljoshare committed Aug 31, 2024
1 parent e68bc9d commit 5379766
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ time = "0.3.36"
assert_cmd = "2.0.14"
criterion = { version = "0.5.1", features = ["html_reports"] }
rstest = "0.22.0"
temp-env = "0.3.6"

[[bench]]
name = "main"
Expand Down
11 changes: 7 additions & 4 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ mod tests {
#[case("DEBUG")]
#[case("TRACE")]
fn get_valid_subscriber(#[case] log_level: String) {
env::set_var("RUST_LOG", &log_level);
assert!(get_subscriber(false).is_ok());
temp_env::with_var("RUST_LOG", Some(&log_level), || {
assert!(get_subscriber(false).is_ok());
env::remove_var("RUST_LOG");
});
}

#[rstest]
fn err_if_level_not_set() {
env::remove_var("RUST_LOG");
assert!(get_subscriber(false).is_err());
temp_env::with_var("RUST_LOG", None::<&str>, || {
assert!(get_subscriber(false).is_err());
});
}
}

0 comments on commit 5379766

Please sign in to comment.