zebrad: Create zebrad.toml in acceptance tests from ZebradConfig
Fixes #929
This commit is contained in:
parent
e90137e79b
commit
991c70723a
|
|
@ -3179,7 +3179,6 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"regex",
|
"regex",
|
||||||
"spandoc",
|
"spandoc",
|
||||||
"tempdir",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
|
|
@ -3219,6 +3218,7 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"serde",
|
"serde",
|
||||||
|
"tempdir",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ color-eyre = "0.5"
|
||||||
tracing = "0.1.19"
|
tracing = "0.1.19"
|
||||||
tracing-subscriber = "0.2.11"
|
tracing-subscriber = "0.2.11"
|
||||||
tracing-error = "0.1.2"
|
tracing-error = "0.1.2"
|
||||||
tempdir = "0.3.7"
|
|
||||||
spandoc = "0.2.0"
|
spandoc = "0.2.0"
|
||||||
regex = "1.3.9"
|
regex = "1.3.9"
|
||||||
thiserror = "1.0.20"
|
thiserror = "1.0.20"
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@ use color_eyre::{
|
||||||
eyre::{eyre, Context, Report, Result},
|
eyre::{eyre, Context, Report, Result},
|
||||||
Help, SectionExt,
|
Help, SectionExt,
|
||||||
};
|
};
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command, ExitStatus, Output};
|
use std::process::{Child, Command, ExitStatus, Output};
|
||||||
use std::{fs, io::Write, path::PathBuf};
|
|
||||||
use tempdir::TempDir;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::process::ExitStatusExt;
|
use std::os::unix::process::ExitStatusExt;
|
||||||
|
|
@ -17,28 +16,6 @@ pub fn test_cmd(command_path: &str, tempdir: &PathBuf) -> Result<Command> {
|
||||||
Ok(cmd)
|
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 {
|
pub trait CommandExt {
|
||||||
/// wrapper for `status` fn on `Command` that constructs informative error
|
/// wrapper for `status` fn on `Command` that constructs informative error
|
||||||
/// reports
|
/// reports
|
||||||
|
|
|
||||||
|
|
@ -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 std::process::Stdio;
|
||||||
|
|
||||||
pub use tempdir::TempDir;
|
|
||||||
|
|
||||||
pub use color_eyre;
|
pub use color_eyre;
|
||||||
pub use color_eyre::eyre;
|
pub use color_eyre::eyre;
|
||||||
pub use eyre::Result;
|
pub use eyre::Result;
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,5 @@ inferno = { version = "0.10.0", default-features = false }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
abscissa_core = { version = "0.5", features = ["testing"] }
|
abscissa_core = { version = "0.5", features = ["testing"] }
|
||||||
once_cell = "1.4"
|
once_cell = "1.4"
|
||||||
|
tempdir = "0.3.7"
|
||||||
zebra-test = { path = "../zebra-test" }
|
zebra-test = { path = "../zebra-test" }
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,31 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
use color_eyre::eyre::Result;
|
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 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> {
|
pub fn get_child(args: &[&str], tempdir: &PathBuf) -> Result<TestChild> {
|
||||||
let mut cmd = test_cmd(env!("CARGO_BIN_EXE_zebrad"), &tempdir)?;
|
let mut cmd = test_cmd(env!("CARGO_BIN_EXE_zebrad"), &tempdir)?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue