fix: use tempdir when testing static files (#6962)

This commit is contained in:
Abner Zheng
2024-03-16 20:57:18 +08:00
committed by GitHub
parent 5e9e21dec5
commit 3b4726a714
10 changed files with 88 additions and 96 deletions

View File

@ -163,6 +163,7 @@ pub mod test_utils {
use reth_libmdbx::MaxReadTransactionDuration;
use reth_primitives::fs;
use std::{path::PathBuf, sync::Arc};
use tempfile::TempDir;
/// Error during database open
pub const ERROR_DB_OPEN: &str = "Not able to open the database file.";
@ -233,12 +234,10 @@ pub mod test_utils {
}
/// Create static_files path for testing
pub fn create_test_static_files_dir() -> PathBuf {
let path = tempdir_path();
let emsg = format!("{}: {:?}", ERROR_STATIC_FILES_CREATION, path);
reth_primitives::fs::create_dir_all(path.clone()).expect(&emsg);
path
pub fn create_test_static_files_dir() -> (TempDir, PathBuf) {
let temp_dir = TempDir::with_prefix("reth-test-static-").expect(ERROR_TEMPDIR);
let path = temp_dir.path().to_path_buf();
(temp_dir, path)
}
/// Get a temporary directory path to use for the database