Skip to main content

oximedia_proxy/validation/
report.rs

1//! Validation report generation.
2
3/// Validation report.
4#[derive(Debug, Clone)]
5pub struct ValidationReport {
6    /// Total number of links checked.
7    pub total_links: usize,
8
9    /// Number of valid links.
10    pub valid_links: usize,
11
12    /// List of errors found.
13    pub errors: Vec<String>,
14
15    /// List of warnings.
16    pub warnings: Vec<String>,
17}
18
19impl ValidationReport {
20    /// Check if validation passed (no errors).
21    #[must_use]
22    pub fn is_valid(&self) -> bool {
23        self.errors.is_empty()
24    }
25
26    /// Get the number of errors.
27    #[must_use]
28    pub fn error_count(&self) -> usize {
29        self.errors.len()
30    }
31
32    /// Get the number of warnings.
33    #[must_use]
34    pub fn warning_count(&self) -> usize {
35        self.warnings.len()
36    }
37
38    /// Generate a summary string.
39    #[must_use]
40    pub fn summary(&self) -> String {
41        format!(
42            "Validation: {} valid / {} total - {} errors, {} warnings",
43            self.valid_links,
44            self.total_links,
45            self.error_count(),
46            self.warning_count()
47        )
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_validation_report() {
57        let report = ValidationReport {
58            total_links: 10,
59            valid_links: 8,
60            errors: vec!["Error 1".to_string()],
61            warnings: vec!["Warning 1".to_string()],
62        };
63
64        assert!(!report.is_valid());
65        assert_eq!(report.error_count(), 1);
66        assert_eq!(report.warning_count(), 1);
67    }
68
69    #[test]
70    fn test_valid_report() {
71        let report = ValidationReport {
72            total_links: 5,
73            valid_links: 5,
74            errors: Vec::new(),
75            warnings: Vec::new(),
76        };
77
78        assert!(report.is_valid());
79        assert_eq!(report.error_count(), 0);
80    }
81}