zebrad: Create zebrad.toml in acceptance tests from ZebradConfig

Fixes #929
This commit is contained in:
Ramana Venkata 2020-08-23 05:15:03 +05:30 committed by Deirdre Connolly
parent e90137e79b
commit 991c70723a
6 changed files with 28 additions and 30 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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"

View File

@ -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<Command> {
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

View File

@ -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;

View File

@ -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" }

View File

@ -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<TestChild> {
let mut cmd = test_cmd(env!("CARGO_BIN_EXE_zebrad"), &tempdir)?;