2020-07-31 23:15:26 -07:00
|
|
|
//! Acceptance test: runs zebrad as a subprocess and asserts its
|
2019-08-29 14:46:54 -07:00
|
|
|
//! output for given argument combinations matches what is expected.
|
2020-07-31 23:15:26 -07:00
|
|
|
|
|
|
|
#![warn(warnings, missing_docs, trivial_casts, unused_qualifications)]
|
2019-08-29 14:46:54 -07:00
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
|
2020-07-31 23:15:26 -07:00
|
|
|
use color_eyre::eyre::Result;
|
|
|
|
use std::time::Duration;
|
|
|
|
use zebra_test::prelude::*;
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
pub fn get_child(args: &[&str]) -> Result<(zebra_test::command::TestChild, impl Drop)> {
|
2020-07-31 23:15:26 -07:00
|
|
|
let (mut cmd, guard) = test_cmd(env!("CARGO_BIN_EXE_zebrad"))?;
|
|
|
|
|
|
|
|
Ok((
|
|
|
|
cmd.args(args)
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.stderr(Stdio::piped())
|
|
|
|
.spawn2()
|
|
|
|
.unwrap(),
|
|
|
|
guard,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn generate_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["generate"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_success()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"# Default configuration for zebrad.")?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn generate_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// unexpected free argument `argument`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["generate", "argument"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// unrecognized option `-f`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["generate", "-f"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// missing argument to option `-o`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["generate", "-o"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// Valid
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["generate", "-o", "file.yaml"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_success()?;
|
2019-08-29 14:46:54 -07:00
|
|
|
|
2020-07-31 23:15:26 -07:00
|
|
|
// Todo: Check if the file was created
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["help"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_success()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"USAGE:")?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// The subcommand "argument" wasn't recognized.
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["help", "argument"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// option `-f` does not accept an argument
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["help", "-f"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-08-29 14:46:54 -07:00
|
|
|
|
|
|
|
#[test]
|
2020-07-31 23:15:26 -07:00
|
|
|
fn revhex_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// Valid
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["revhex", "33eeff55"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_success()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"55ffee33")?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn seed_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (mut child, _guard) = get_child(&["-v", "seed"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
|
|
|
|
// Run the program and kill it at 1 second
|
|
|
|
std::thread::sleep(Duration::from_secs(1));
|
|
|
|
child.kill()?;
|
|
|
|
|
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_failure()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"Starting zebrad in seed mode")?;
|
|
|
|
|
2020-08-04 13:38:39 -07:00
|
|
|
// Make sure the command was killed
|
|
|
|
assert!(output.was_killed());
|
|
|
|
|
2020-07-31 23:15:26 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn seed_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// unexpected free argument `argument`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["seed", "argument"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// unrecognized option `-f`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["seed", "-f"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// unexpected free argument `start`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["seed", "start"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn start_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (mut child, _guard) = get_child(&["-v", "start"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
|
|
|
|
// Run the program and kill it at 1 second
|
|
|
|
std::thread::sleep(Duration::from_secs(1));
|
|
|
|
child.kill()?;
|
|
|
|
|
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_failure()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"Starting zebrad")?;
|
|
|
|
|
2020-08-04 13:38:39 -07:00
|
|
|
// Make sure the command was killed
|
|
|
|
assert!(output.was_killed());
|
|
|
|
|
2020-07-31 23:15:26 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn start_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// Any free argument is valid
|
2020-08-06 10:29:31 -07:00
|
|
|
let (mut child, _guard) = get_child(&["start", "argument"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
// Run the program and kill it at 1 second
|
|
|
|
std::thread::sleep(Duration::from_secs(1));
|
|
|
|
child.kill()?;
|
|
|
|
let output = child.wait_with_output()?;
|
2020-08-04 13:38:39 -07:00
|
|
|
|
|
|
|
// Make sure the command was killed
|
|
|
|
assert!(output.was_killed());
|
|
|
|
|
2020-07-31 23:15:26 -07:00
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// unrecognized option `-f`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["start", "-f"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&[])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_success()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"USAGE:")?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_no_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["version"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
let output = output.assert_success()?;
|
|
|
|
|
|
|
|
output.stdout_contains(r"zebrad [0-9].[0-9].[0-9]")?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_args() -> Result<()> {
|
|
|
|
zebra_test::init();
|
|
|
|
|
|
|
|
// unexpected free argument `argument`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["version", "argument"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
// unrecognized option `-f`
|
2020-08-06 10:29:31 -07:00
|
|
|
let (child, _guard) = get_child(&["version", "-f"])?;
|
2020-07-31 23:15:26 -07:00
|
|
|
let output = child.wait_with_output()?;
|
|
|
|
output.assert_failure()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn serialized_tests() -> Result<()> {
|
|
|
|
start_no_args()?;
|
|
|
|
start_args()?;
|
|
|
|
seed_no_args()?;
|
|
|
|
|
|
|
|
Ok(())
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|