use std::process::{Command, Output};
fn probe(flag: &str) -> Output {
Command::new(env!("CARGO_BIN_EXE_shep-deploy"))
.arg(flag)
.env_remove("SHEP_HOME")
.env_remove("SHEP_DOG_NAME")
.output()
.expect("the test binary's own sibling is on disk")
}
#[test]
fn the_version_answer_is_the_one_shep_reads() {
let output = probe("--version");
assert!(output.status.success(), "{:?}", output.status);
let text = String::from_utf8(output.stdout).expect("the answer is text");
let answer = shep_client::shep_core::dogs::parse_version_answer(&text)
.expect("the answer shep's own parser cannot read is the bug this pins");
assert_eq!(answer.version, env!("CARGO_PKG_VERSION"));
assert_eq!(
answer.protocol,
Some(shep_client::PROTOCOL_VERSION),
"the protocol answered is the one this binary was compiled against"
);
}
#[test]
fn the_schema_answer_is_json_describing_this_dogs_own_section() {
let output = probe("--schema");
assert!(output.status.success(), "{:?}", output.status);
let schema: serde_json::Value =
serde_json::from_slice(&output.stdout).expect("the answer is JSON");
assert_eq!(
schema.get("title").and_then(serde_json::Value::as_str),
Some("deploy"),
"the pane heads its form with this, so it names the section rather than the Rust type"
);
assert!(
schema.pointer("/properties/interval").is_some(),
"the section's own keys are what the schema describes"
);
}
#[test]
fn an_ordinary_argument_is_not_a_probe() {
let output = probe("--not-a-flag-this-dog-knows");
assert!(
!output.status.success(),
"an unknown flag is still a usage error"
);
assert!(
output.stdout.is_empty(),
"nothing is printed to stdout, so shep cannot read a usage message as an answer"
);
}