#[cfg(test)]
mod tests {
use axum_test::TestServer;
use serde_json::json;
async fn create_test_app() -> axum::Router {
use axum::{routing::get, Router};
Router::new()
.route("/health", get(|| async { "OK" }))
.route("/v1/models", get(|| async {
axum::Json(json!({
"object": "list",
"data": []
}))
}))
.route("/v1/chat/completions", axum::routing::post(|| async {
axum::Json(json!({
"error": {
"message": "Not implemented in test",
"type": "test_error"
}
}))
}))
}
#[tokio::test]
async fn test_health_check() {
let app = create_test_app().await;
let server = TestServer::new(app).unwrap();
let response = server
.get("/health")
.await;
response.assert_status_ok();
response.assert_text("OK");
}
#[tokio::test]
async fn test_list_models() {
let app = create_test_app().await;
let server = TestServer::new(app).unwrap();
let response = server
.get("/v1/models")
.await;
response.assert_status_ok();
let json = response.json::<serde_json::Value>();
assert_eq!(json["object"], "list");
assert!(json["data"].is_array());
}
#[tokio::test]
async fn test_chat_completion_missing_messages() {
let app = create_test_app().await;
let server = TestServer::new(app).unwrap();
let response = server
.post("/v1/chat/completions")
.json(&json!({
"model": "claude-3-opus-20240229",
"messages": []
}))
.await;
response.assert_status_ok();
}
}