Skip to content

Commit

Permalink
appender: replace tempdir with tempfile
Browse files Browse the repository at this point in the history
`tracing-appender`'s tests use the `tempdir` crate, which is no longer
actively maintained, and `cargo audit` complains about it. The
`tempfile` crate is the suggested replacement.

This commit replaces `tempdir` with `tempfile` in the tests for
`tracing-appender`.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Aug 16, 2021
1 parent 81aa158 commit 256ff1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tracing-appender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ features = ["fmt"]

[dev-dependencies]
tracing = { path = "../tracing", version = "0.2" }
tempdir = "0.3"
tempfile = "3"
28 changes: 6 additions & 22 deletions tracing-appender/src/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ mod test {
use super::*;
use std::fs;
use std::io::Write;
use tempdir::TempDir;

fn find_str_in_log(dir_path: &Path, expected_value: &str) -> bool {
let dir_contents = fs::read_dir(dir_path).expect("Failed to read directory");
Expand All @@ -367,7 +366,8 @@ mod test {
appender.flush().expect("Failed to flush!");
}

fn test_appender(rotation: Rotation, directory: TempDir, file_prefix: &str) {
fn test_appender(rotation: Rotation, file_prefix: &str) {
let directory = tempfile::tempdir().expect("failed to create tempdir");
let mut appender = RollingFileAppender::new(rotation, directory.path(), file_prefix);

let expected_value = "Hello";
Expand All @@ -381,38 +381,22 @@ mod test {

#[test]
fn write_minutely_log() {
test_appender(
Rotation::HOURLY,
TempDir::new("minutely").expect("Failed to create tempdir"),
"minutely.log",
);
test_appender(Rotation::HOURLY, "minutely.log");
}

#[test]
fn write_hourly_log() {
test_appender(
Rotation::HOURLY,
TempDir::new("hourly").expect("Failed to create tempdir"),
"hourly.log",
);
test_appender(Rotation::HOURLY, "hourly.log");
}

#[test]
fn write_daily_log() {
test_appender(
Rotation::DAILY,
TempDir::new("daily").expect("Failed to create tempdir"),
"daily.log",
);
test_appender(Rotation::DAILY, "daily.log");
}

#[test]
fn write_never_log() {
test_appender(
Rotation::NEVER,
TempDir::new("never").expect("Failed to create tempdir"),
"never.log",
);
test_appender(Rotation::NEVER, "never.log");
}

#[test]
Expand Down

0 comments on commit 256ff1d

Please sign in to comment.