sdk_relay/tests/http_health.rs

24 lines
887 B
Rust

use std::time::Duration;
#[tokio::test]
async fn http_health_endpoint_should_return_healthy() {
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
.expect("cannot build client");
let url = std::env::var("SDK_RELAY_HTTP").unwrap_or_else(|_| "http://localhost:8091".to_string());
let resp = client.get(format!("{}/health", url)).send().await;
if resp.is_err() {
eprintln!("sdk_relay HTTP indisponible, test /health ignoré");
return;
}
let res = resp.expect("cannot call /health");
assert!(res.status().is_success(), "status: {}", res.status());
let json: serde_json::Value = res.json().await.expect("invalid json");
let status = json.get("status").and_then(|v| v.as_str()).unwrap_or("");
assert_eq!(status, "healthy", "health status should be healthy, got: {}", status);
}