diff --git a/Cargo.lock b/Cargo.lock index f828fd42..929b2d27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3179,7 +3179,6 @@ dependencies = [ "lazy_static", "regex", "spandoc", - "tempdir", "thiserror", "tokio", "tower", @@ -3219,6 +3218,7 @@ dependencies = [ "once_cell", "rand 0.7.3", "serde", + "tempdir", "thiserror", "tokio", "toml", diff --git a/zebra-test/Cargo.toml b/zebra-test/Cargo.toml index 53568561..d139717b 100644 --- a/zebra-test/Cargo.toml +++ b/zebra-test/Cargo.toml @@ -16,7 +16,6 @@ color-eyre = "0.5" tracing = "0.1.19" tracing-subscriber = "0.2.11" tracing-error = "0.1.2" -tempdir = "0.3.7" spandoc = "0.2.0" regex = "1.3.9" thiserror = "1.0.20" diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index 88f94f7f..94e78aa9 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -2,9 +2,8 @@ use color_eyre::{ eyre::{eyre, Context, Report, Result}, Help, SectionExt, }; +use std::path::PathBuf; use std::process::{Child, Command, ExitStatus, Output}; -use std::{fs, io::Write, path::PathBuf}; -use tempdir::TempDir; #[cfg(unix)] use std::os::unix::process::ExitStatusExt; @@ -17,28 +16,6 @@ pub fn test_cmd(command_path: &str, tempdir: &PathBuf) -> Result { Ok(cmd) } -/// Create a temp directory and optional config file -pub fn tempdir(create_config: bool) -> Result<(PathBuf, impl Drop)> { - let dir = TempDir::new("zebrad_tests")?; - - if create_config { - let cache_dir = dir.path().join("state"); - fs::create_dir(&cache_dir)?; - fs::File::create(dir.path().join("zebrad.toml"))?.write_all( - format!( - "[state]\ncache_dir = '{}'\nmemory_cache_bytes = 256000000\n[network]\nlisten_addr = '127.0.0.1:0'\n", - cache_dir - .into_os_string() - .into_string() - .map_err(|_| eyre!("tmp dir path cannot be encoded as UTF8"))? - ) - .as_bytes(), - )?; - } - - Ok((dir.path().to_path_buf(), dir)) -} - pub trait CommandExt { /// wrapper for `status` fn on `Command` that constructs informative error /// reports diff --git a/zebra-test/src/prelude.rs b/zebra-test/src/prelude.rs index cd28ee3a..3f9cd33f 100644 --- a/zebra-test/src/prelude.rs +++ b/zebra-test/src/prelude.rs @@ -1,8 +1,6 @@ -pub use crate::command::{tempdir, test_cmd, CommandExt, TestChild}; +pub use crate::command::{test_cmd, CommandExt, TestChild}; pub use std::process::Stdio; -pub use tempdir::TempDir; - pub use color_eyre; pub use color_eyre::eyre; pub use eyre::Result; diff --git a/zebrad/Cargo.toml b/zebrad/Cargo.toml index b7632bc5..4de181df 100644 --- a/zebrad/Cargo.toml +++ b/zebrad/Cargo.toml @@ -40,4 +40,5 @@ inferno = { version = "0.10.0", default-features = false } [dev-dependencies] abscissa_core = { version = "0.5", features = ["testing"] } once_cell = "1.4" +tempdir = "0.3.7" zebra-test = { path = "../zebra-test" } diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index c91141b7..f9cd70c9 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -5,8 +5,31 @@ #![forbid(unsafe_code)] use color_eyre::eyre::Result; -use std::{path::PathBuf, time::Duration}; +use std::{fs, io::Write, path::PathBuf, time::Duration}; +use tempdir::TempDir; +use toml; + use zebra_test::prelude::*; +use zebrad::config::ZebradConfig; + +pub fn tempdir(create_config: bool) -> Result<(PathBuf, impl Drop)> { + let dir = TempDir::new("zebrad_tests")?; + + if create_config { + let cache_dir = dir.path().join("state"); + fs::create_dir(&cache_dir)?; + + let mut config = ZebradConfig::default(); + config.state.cache_dir = cache_dir; + config.state.memory_cache_bytes = 256000000; + config.network.listen_addr = "127.0.0.1:0".parse()?; + + fs::File::create(dir.path().join("zebrad.toml"))? + .write_all(toml::to_string(&config)?.as_bytes())?; + } + + Ok((dir.path().to_path_buf(), dir)) +} pub fn get_child(args: &[&str], tempdir: &PathBuf) -> Result { let mut cmd = test_cmd(env!("CARGO_BIN_EXE_zebrad"), &tempdir)?;