use std::time::Duration;
#[tokio::test]
async fn test_health_endpoint() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client.get("http://localhost:8580/health").send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_eq!(response.status(), 200);
let body: serde_json::Value = response.json().await.unwrap();
assert_eq!(body["status"], "healthy");
assert!(body["service"].as_str().is_some());
assert!(body["version"].as_str().is_some());
}
#[tokio::test]
async fn test_health_no_auth_required() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client.get("http://localhost:8580/health").send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_ne!(response.status(), 401);
assert_eq!(response.status(), 200);
}
#[tokio::test]
async fn test_status_endpoint_with_auth() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client
.get("http://localhost:8580/v1/status")
.header("X-API-Key", "sk_test_key")
.send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_ne!(response.status(), 404);
}
#[tokio::test]
async fn test_status_requires_auth() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client.get("http://localhost:8580/v1/status").send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_eq!(response.status(), 401);
}
#[tokio::test]
async fn test_docs_endpoint() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client.get("http://localhost:8580/docs").send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_eq!(response.status(), 200);
let content_type = response.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("");
assert!(content_type.contains("text/html"));
}
#[tokio::test]
async fn test_openapi_endpoint() {
let client = reqwest::Client::new();
let result = tokio::time::timeout(
Duration::from_secs(5),
client.get("http://localhost:8580/openapi.json").send()
).await;
let response = match result {
Ok(Ok(resp)) => resp,
_ => {
println!("⚠️ Servidor não está rodando, pulando teste");
return;
}
};
assert_eq!(response.status(), 200);
let body: serde_json::Value = response.json().await.unwrap();
assert!(body.get("openapi").is_some() || body.get("swagger").is_some());
}