sdk_relay/tests/http_health.rs

23 lines
785 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 res = client
.get(format!("{}/health", url))
.send()
.await
.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);
}