From 5485f4429a05f7fbabf763f16d03ec85a6b59ee6 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 3 Sep 2020 17:13:23 -0300 Subject: [PATCH] Add config path to acceptance tests (#946) * add and apply config mode to get_child * remove option to read config from current directory * remove argument from get_child --- zebrad/src/commands.rs | 3 --- zebrad/src/commands/generate.rs | 2 +- zebrad/tests/acceptance.rs | 13 +++++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/zebrad/src/commands.rs b/zebrad/src/commands.rs index aeba33b8..1809029a 100644 --- a/zebrad/src/commands.rs +++ b/zebrad/src/commands.rs @@ -71,9 +71,6 @@ impl Configurable for ZebradCmd { dirs::preference_dir() .map(|path| path.join(CONFIG_FILE)) .and_then(if_exists) - .or_else(|| std::env::current_dir().ok()) - .map(|path| path.join(CONFIG_FILE)) - .and_then(if_exists) // Note: Changes in how configuration is loaded may need usage // edits in generate.rs diff --git a/zebrad/src/commands/generate.rs b/zebrad/src/commands/generate.rs index 4ac701d2..1f3f4027 100644 --- a/zebrad/src/commands/generate.rs +++ b/zebrad/src/commands/generate.rs @@ -34,7 +34,7 @@ impl Runnable for GenerateCmd { # zebrad start # # If there is no -c flag on the command line, zebrad looks for zebrad.toml in -# the current directory. If that file does not exist, zebrad uses the default +# the user's preference directory. If that file does not exist, zebrad uses the default # config. " diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 503a513c..c35bca8b 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -46,9 +46,13 @@ fn tempdir(config_mode: ConfigMode) -> Result<(PathBuf, impl Drop)> { Ok((dir.path().to_path_buf(), dir)) } -pub fn get_child(args: &[&str], tempdir: &PathBuf) -> Result { +fn get_child(args: &[&str], tempdir: &PathBuf) -> Result { let mut cmd = test_cmd(env!("CARGO_BIN_EXE_zebrad"), &tempdir)?; + let default_config_path = tempdir.join("zebrad.toml"); + if default_config_path.exists() { + cmd.args(&["-c", default_config_path.to_str().unwrap()]); + } Ok(cmd .args(args) .stdout(Stdio::piped()) @@ -150,7 +154,7 @@ fn help_no_args() -> Result<()> { #[test] fn help_args() -> Result<()> { zebra_test::init(); - let (tempdir, _guard) = tempdir(ConfigMode::Ephemeral)?; + let (tempdir, _guard) = tempdir(ConfigMode::NoConfig)?; // The subcommand "argument" wasn't recognized. let child = get_child(&["help", "argument"], &tempdir)?; @@ -431,10 +435,7 @@ fn valid_generated_config(command: &str, expected_output: &str) -> Result<()> { assert_with_context!(generated_config_path.exists(), &output); // Run command using temp dir and kill it at 1 second - let mut child = get_child( - &["-c", generated_config_path.to_str().unwrap(), command], - &tempdir, - )?; + let mut child = get_child(&[command], &tempdir)?; std::thread::sleep(Duration::from_secs(1)); child.kill()?;