#[cfg(test)]
mod tests {
use super::super::http::HttpThrottleRequest;
use crate::types::ThrottleResponse;
#[tokio::test]
async fn test_http_transport_basic() {
let request = HttpThrottleRequest {
key: "test_key".to_string(),
max_burst: 10,
count_per_period: 20,
period: 60,
quantity: Some(1),
};
let json = serde_json::to_string(&request).unwrap();
assert!(json.contains("test_key"));
let response_json = r#"{
"allowed": true,
"limit": 10,
"remaining": 9,
"reset_after": 60,
"retry_after": 0
}"#;
let response: ThrottleResponse = serde_json::from_str(response_json).unwrap();
assert!(response.allowed);
assert_eq!(response.limit, 10);
assert_eq!(response.remaining, 9);
}
#[tokio::test]
async fn test_http_request_validation() {
let request_json = r#"{
"key": "test",
"max_burst": 5,
"count_per_period": 10,
"period": 60
}"#;
let request: HttpThrottleRequest = serde_json::from_str(request_json).unwrap();
assert_eq!(request.quantity, None);
}
}