//! `wai-ingest --config --check` (what `wai serve ingest --check` runs): the configuration //! read by the gateway's own reader, as it starts from it, and nothing started; one it does not read //! is refused, exit 1, with the reason. use std::path::Path; use std::process::{Command, Output, Stdio}; fn check(file: &Path) -> Output { Command::new(env!("CARGO_BIN_EXE_wai-ingest")).arg("--config").arg(file).arg("--check").stdin(Stdio::null()).output().expect("wai-ingest runs") } #[test] fn check_reads_the_configuration_and_starts_nothing() { let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("gateway.example.toml"); let o = check(&example); assert!(o.status.success(), "{}", String::from_utf8_lossy(&o.stderr)); assert_eq!(String::from_utf8_lossy(&o.stdout), format!("wai-ingest: {} reads as the gateway would start from it\n", example.display())); let d = std::env::temp_dir().join(format!("wai-ingest-check-{}", std::process::id())); std::fs::create_dir_all(&d).unwrap(); let text = std::fs::read_to_string(&example).unwrap(); let bad = d.join("bad.toml"); std::fs::write(&bad, text.replacen("listen = \"127.0.0.1:8088\"", "listen = \"nowhere\"", 1)).unwrap(); let o = check(&bad); assert_eq!(o.status.code(), Some(1), "{}", String::from_utf8_lossy(&o.stdout)); assert!(o.stdout.is_empty() && String::from_utf8_lossy(&o.stderr).starts_with(&format!("wai-ingest: {}: ", bad.display())), "{}", String::from_utf8_lossy(&o.stderr)); let o = check(&d.join("gone.toml")); assert_eq!(o.status.code(), Some(1)); let _ = std::fs::remove_dir_all(&d); }