appender: replace tempdir with tempfile

`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 <eliza@buoyant.io>
This commit is contained in:
Eliza Weisman 2021-08-16 10:30:25 -07:00
parent cc40b68ed0
commit edc85a9ba8
2 changed files with 7 additions and 23 deletions

View File

@ -31,4 +31,4 @@ features = ["fmt"]
[dev-dependencies]
tracing = { path = "../tracing", version = "0.1" }
tempdir = "0.3"
tempfile = "3"

View File

@ -351,7 +351,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");
@ -375,7 +374,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";
@ -389,38 +389,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]