Skip to content

Commit 9ec5492

Browse files
authored
feat: add comprehensive Rust API tests with positive and negative cases (#27)
Implement 44 comprehensive unit tests for the Rust Actix-web API following industry best practices for API testing: Test Coverage: - Root endpoint tests (4 tests) - Health endpoint tests (11 tests: positive + negative) - Vault endpoint tests (5 tests: positive + negative) - Cache endpoint tests (13 tests: GET/POST/DELETE + edge cases) - Messaging endpoint tests (3 tests) - Redis cluster endpoint tests (6 tests) - Metrics endpoint tests (3 tests) - Edge cases and error handling (9 tests) Key Features: - Positive test cases: Valid inputs, expected success responses - Negative test cases: Invalid inputs, error conditions, edge cases - HTTP status code validation (200, 404, 405, 400, 503) - JSON response structure validation - Empty/missing parameter handling - Special character handling - Very long input handling - Zero/negative TTL handling Test Organization: - Grouped by endpoint/feature for maintainability - Clear test names describing what is being tested - Comprehensive documentation with comments - Macro-based test app creation for DRY code All 44 tests pass successfully with proper error handling and validation of both success and failure scenarios.
1 parent 1588378 commit 9ec5492

File tree

2 files changed

+638
-42
lines changed

2 files changed

+638
-42
lines changed

reference-apps/rust/src/main.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,45 +1340,4 @@ async fn main() -> std::io::Result<()> {
13401340
}
13411341

13421342
#[cfg(test)]
1343-
mod tests {
1344-
use super::*;
1345-
use actix_web::{test, App};
1346-
1347-
#[actix_web::test]
1348-
async fn test_root_endpoint() {
1349-
let app = test::init_service(App::new().route("/", web::get().to(root))).await;
1350-
let req = test::TestRequest::get().uri("/").to_request();
1351-
let resp = test::call_service(&app, req).await;
1352-
1353-
assert!(resp.status().is_success());
1354-
1355-
let body: ApiInfo = test::read_body_json(resp).await;
1356-
assert_eq!(body.name, "DevStack Core Reference API");
1357-
assert_eq!(body.version, "1.0.0");
1358-
assert_eq!(body.language, "Rust");
1359-
assert_eq!(body.framework, "Actix-web");
1360-
}
1361-
1362-
#[actix_web::test]
1363-
async fn test_health_endpoint() {
1364-
let app = test::init_service(App::new().route("/health/", web::get().to(health_simple))).await;
1365-
let req = test::TestRequest::get().uri("/health/").to_request();
1366-
let resp = test::call_service(&app, req).await;
1367-
1368-
assert!(resp.status().is_success());
1369-
1370-
let body: HealthResponse = test::read_body_json(resp).await;
1371-
assert_eq!(body.status, "healthy");
1372-
assert!(body.timestamp.is_some());
1373-
}
1374-
1375-
#[actix_web::test]
1376-
async fn test_metrics_endpoint() {
1377-
register_metrics();
1378-
let app = test::init_service(App::new().route("/metrics", web::get().to(metrics))).await;
1379-
let req = test::TestRequest::get().uri("/metrics").to_request();
1380-
let resp = test::call_service(&app, req).await;
1381-
1382-
assert!(resp.status().is_success());
1383-
}
1384-
}
1343+
mod tests; // Comprehensive test suite in tests.rs

0 commit comments

Comments
 (0)