move env variable creation to test_cmd
This commit is contained in:
parent
2dacd0a62b
commit
5f23970377
|
|
@ -2,6 +2,7 @@ use color_eyre::{
|
||||||
eyre::{eyre, Context, Report, Result},
|
eyre::{eyre, Context, Report, Result},
|
||||||
Help, SectionExt,
|
Help, SectionExt,
|
||||||
};
|
};
|
||||||
|
use std::{env, fs};
|
||||||
use std::process::{Child, Command, ExitStatus, Output};
|
use std::process::{Child, Command, ExitStatus, Output};
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
|
|
@ -11,6 +12,10 @@ pub fn test_cmd(path: &str) -> Result<(Command, impl Drop)> {
|
||||||
let mut cmd = Command::new(path);
|
let mut cmd = Command::new(path);
|
||||||
cmd.current_dir(dir.path());
|
cmd.current_dir(dir.path());
|
||||||
|
|
||||||
|
let state_dir = dir.path().join("state");
|
||||||
|
fs::create_dir(&state_dir)?;
|
||||||
|
env::set_var("ZEBRAD_CACHE_DIR", state_dir);
|
||||||
|
|
||||||
Ok((cmd, dir))
|
Ok((cmd, dir))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use zebra_test::prelude::*;
|
||||||
|
|
||||||
// Todo: The following 3 helper functions can probably be abstracted into one
|
// Todo: The following 3 helper functions can probably be abstracted into one
|
||||||
pub fn get_child_single_arg(arg: &str) -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
pub fn get_child_single_arg(arg: &str) -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
||||||
change_default_path()?;
|
|
||||||
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -24,7 +23,6 @@ pub fn get_child_single_arg(arg: &str) -> Result<(zebra_test::command::TestChild
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_child_multi_args(args: &[&str]) -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
pub fn get_child_multi_args(args: &[&str]) -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
||||||
change_default_path()?;
|
|
||||||
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -38,7 +36,6 @@ pub fn get_child_multi_args(args: &[&str]) -> Result<(zebra_test::command::TestC
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_child_no_args() -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
pub fn get_child_no_args() -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
||||||
change_default_path()?;
|
|
||||||
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -50,13 +47,6 @@ pub fn get_child_no_args() -> Result<(zebra_test::command::TestChild, impl Drop)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_default_path() -> Result<()> {
|
|
||||||
let tmp = TempDir::new("zebrad_tests")?;
|
|
||||||
std::env::set_var("ZEBRAD_CACHE_DIR", tmp.path());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_no_args() -> Result<()> {
|
fn generate_no_args() -> Result<()> {
|
||||||
zebra_test::init();
|
zebra_test::init();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue