use crate::alert_system::{
AlertManager, AlertConfig, NotificationChannel,
EmailNotificationHandler, SlackNotificationHandler,
EscalationPolicy,
};
use crate::monitoring::{HealthAlert, AlertSeverity};
use chrono::Duration;
use std::collections::HashMap;
#[tokio::test]
async fn test_alert_system() {
let config = create_test_alert_config();
let mut alert_manager = AlertManager::new(config);
alert_manager.register_handler(EmailNotificationHandler {
smtp_config: create_test_smtp_config(),
});
alert_manager.register_handler(SlackNotificationHandler {
webhook_url: "https://test.webhook.url".to_string(),
});
let alert = HealthAlert {
severity: AlertSeverity::Critical,
message: "Test critical alert".to_string(),
timestamp: chrono::Utc::now(),
metric_name: "test_metric".to_string(),
threshold: 0.9,
current_value: 0.5,
};
let result = alert_manager.process_alert(alert).await;
assert!(result.is_ok());
}
fn create_test_alert_config() -> AlertConfig {
let mut escalation_policies = HashMap::new();
escalation_policies.insert(
AlertSeverity::Critical,
EscalationPolicy {
initial_delay: Duration::seconds(0),
repeat_interval: Duration::minutes(5),
max_escalations: 3,
notification_channels: vec![
NotificationChannel::Email("admin@test.com".to_string()),
NotificationChannel::Slack("#alerts".to_string()),
],
},
);
AlertConfig {
alert_ttl: Duration::hours(24),
max_alerts_per_window: 100,
notification_channels: vec![
NotificationChannel::Email("default@test.com".to_string()),
],
escalation_policies,
}
}
fn create_test_smtp_config() -> SmtpConfig {
SmtpConfig {
host: "smtp.test.com".to_string(),
port: 587,
username: "test".to_string(),
password: "test".to_string(),
from_address: "alerts@test.com".to_string(),
}
}