mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-24 05:43:58 +00:00
- Run cargo fmt across all crates (468 files formatted) - Add permissions for PR comments in benchmarks.yml - Add continue-on-error for PR comment steps - Remove Docker service from postgres-extension-ci (pgrx manages own postgres) - Add permissions to postgres-extension-ci.yml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
80 lines
2.1 KiB
Rust
80 lines
2.1 KiB
Rust
// API server integration tests
|
|
//
|
|
// Tests HTTP API endpoints, authentication, rate limiting, and async processing
|
|
|
|
use super::*;
|
|
use reqwest::{multipart, Client, StatusCode};
|
|
use serde_json::json;
|
|
use tokio;
|
|
|
|
#[tokio::test]
|
|
async fn test_api_post_text_with_file() {
|
|
let test_server = TestServer::start_api()
|
|
.await
|
|
.expect("Failed to start API server");
|
|
let client = Client::new();
|
|
|
|
// Create test image
|
|
let image = images::generate_simple_equation("x + y");
|
|
image.save("/tmp/api_test.png").unwrap();
|
|
let image_bytes = std::fs::read("/tmp/api_test.png").unwrap();
|
|
|
|
// Create multipart form
|
|
let form = multipart::Form::new().part(
|
|
"file",
|
|
multipart::Part::bytes(image_bytes)
|
|
.file_name("equation.png")
|
|
.mime_str("image/png")
|
|
.unwrap(),
|
|
);
|
|
|
|
// POST to /v3/text
|
|
let response = client
|
|
.post(&format!("{}/v3/text", test_server.base_url()))
|
|
.header("app_id", "test_app_id")
|
|
.header("app_key", "test_app_key")
|
|
.multipart(form)
|
|
.send()
|
|
.await
|
|
.expect("Request failed");
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
|
|
let result: serde_json::Value = response.json().await.unwrap();
|
|
assert!(result.get("request_id").is_some(), "Should have request_id");
|
|
assert!(result.get("text").is_some(), "Should have text field");
|
|
assert!(
|
|
result.get("processing_time_ms").is_some(),
|
|
"Should have processing time"
|
|
);
|
|
|
|
test_server.shutdown().await;
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_api_authentication_validation() {
|
|
let test_server = TestServer::start_api()
|
|
.await
|
|
.expect("Failed to start API server");
|
|
let client = Client::new();
|
|
|
|
let payload = json!({
|
|
"src": "base64data"
|
|
});
|
|
|
|
// Test missing auth
|
|
let response = client
|
|
.post(&format!("{}/v3/text", test_server.base_url()))
|
|
.json(&payload)
|
|
.send()
|
|
.await
|
|
.expect("Request failed");
|
|
|
|
assert_eq!(
|
|
response.status(),
|
|
StatusCode::UNAUTHORIZED,
|
|
"Should require authentication"
|
|
);
|
|
|
|
test_server.shutdown().await;
|
|
}
|