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
This commit is contained in:
Alfredo Garcia 2020-09-03 17:13:23 -03:00 committed by GitHub
parent d3f7af7114
commit 5485f4429a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View File

@ -71,9 +71,6 @@ impl Configurable<ZebradConfig> for ZebradCmd {
dirs::preference_dir() dirs::preference_dir()
.map(|path| path.join(CONFIG_FILE)) .map(|path| path.join(CONFIG_FILE))
.and_then(if_exists) .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 // Note: Changes in how configuration is loaded may need usage
// edits in generate.rs // edits in generate.rs

View File

@ -34,7 +34,7 @@ impl Runnable for GenerateCmd {
# zebrad start # zebrad start
# #
# If there is no -c flag on the command line, zebrad looks for zebrad.toml in # 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. # config.
" "

View File

@ -46,9 +46,13 @@ fn tempdir(config_mode: ConfigMode) -> Result<(PathBuf, impl Drop)> {
Ok((dir.path().to_path_buf(), dir)) Ok((dir.path().to_path_buf(), dir))
} }
pub fn get_child(args: &[&str], tempdir: &PathBuf) -> Result<TestChild> { 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)?;
let default_config_path = tempdir.join("zebrad.toml");
if default_config_path.exists() {
cmd.args(&["-c", default_config_path.to_str().unwrap()]);
}
Ok(cmd Ok(cmd
.args(args) .args(args)
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -150,7 +154,7 @@ fn help_no_args() -> Result<()> {
#[test] #[test]
fn help_args() -> Result<()> { fn help_args() -> Result<()> {
zebra_test::init(); zebra_test::init();
let (tempdir, _guard) = tempdir(ConfigMode::Ephemeral)?; let (tempdir, _guard) = tempdir(ConfigMode::NoConfig)?;
// The subcommand "argument" wasn't recognized. // The subcommand "argument" wasn't recognized.
let child = get_child(&["help", "argument"], &tempdir)?; 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); assert_with_context!(generated_config_path.exists(), &output);
// Run command using temp dir and kill it at 1 second // Run command using temp dir and kill it at 1 second
let mut child = get_child( let mut child = get_child(&[command], &tempdir)?;
&["-c", generated_config_path.to_str().unwrap(), command],
&tempdir,
)?;
std::thread::sleep(Duration::from_secs(1)); std::thread::sleep(Duration::from_secs(1));
child.kill()?; child.kill()?;