use std::process::Command;
fn cargo() -> String {
std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string())
}
#[test]
fn http_service_example_exercises_the_documented_surface() {
let output = Command::new(cargo())
.args(["run", "-q", "-p", "axum-helpers", "--example", "http_service"])
.env("CORS_ALLOWED_ORIGIN", "http://localhost:3000")
.output()
.expect("failed to spawn cargo run --example http_service");
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
output.status.success(),
"example exited with {}\n--- stdout ---\n{stdout}\n--- stderr ---\n{stderr}",
output.status,
);
for marker in [
"step:listening",
"step:health status=200",
"step:created status=201",
"step:rejected status=400 error=VALIDATION_ERROR",
"step:bad_uuid status=400",
"step:not_found status=404 error=NOT_FOUND",
"step:fallback status=404",
"HTTP walkthrough complete",
] {
assert!(
stdout.contains(marker),
"example output missing {marker:?}\n--- stdout ---\n{stdout}",
);
}
}
#[test]
fn http_service_example_fails_without_cors_config() {
let output = Command::new(cargo())
.args(["run", "-q", "-p", "axum-helpers", "--example", "http_service"])
.env_remove("CORS_ALLOWED_ORIGIN")
.output()
.expect("failed to spawn cargo run --example http_service");
assert!(
!output.status.success(),
"example reported success without CORS_ALLOWED_ORIGIN\n--- stdout ---\n{}",
String::from_utf8_lossy(&output.stdout),
);
}