Skip to main content

oximedia_proxy/validation/
checker.rs

1//! Validation checker for proxy workflows.
2
3use super::report::ValidationReport;
4use crate::{ProxyLinkManager, Result};
5
6/// Validation checker for proxy workflows.
7pub struct ValidationChecker<'a> {
8    link_manager: &'a ProxyLinkManager,
9}
10
11impl<'a> ValidationChecker<'a> {
12    /// Create a new validation checker.
13    #[must_use]
14    pub const fn new(link_manager: &'a ProxyLinkManager) -> Self {
15        Self { link_manager }
16    }
17
18    /// Validate all proxy links.
19    pub fn validate(&self) -> Result<ValidationReport> {
20        let all_links = self.link_manager.all_links();
21        let total = all_links.len();
22        let mut errors = Vec::new();
23        let mut warnings = Vec::new();
24
25        for link in &all_links {
26            // Check if files exist
27            if !link.proxy_path.exists() {
28                errors.push(format!(
29                    "Proxy file not found: {}",
30                    link.proxy_path.display()
31                ));
32            }
33
34            if !link.original_path.exists() {
35                errors.push(format!(
36                    "Original file not found: {}",
37                    link.original_path.display()
38                ));
39            }
40
41            // Check for potential issues
42            if link.duration == 0.0 {
43                warnings.push(format!(
44                    "Zero duration for link: {}",
45                    link.proxy_path.display()
46                ));
47            }
48        }
49
50        Ok(ValidationReport {
51            total_links: total,
52            valid_links: total - errors.len() / 2,
53            errors,
54            warnings,
55        })
56    }
57
58    /// Quick validation check (just existence).
59    pub fn quick_validate(&self) -> Result<bool> {
60        let all_links = self.link_manager.all_links();
61
62        for link in &all_links {
63            if !link.proxy_path.exists() || !link.original_path.exists() {
64                return Ok(false);
65            }
66        }
67
68        Ok(true)
69    }
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[tokio::test]
77    async fn test_validation_checker() {
78        let temp_dir = std::env::temp_dir();
79        let db_path = temp_dir.join("test_validation.json");
80
81        let manager = ProxyLinkManager::new(&db_path)
82            .await
83            .expect("should succeed in test");
84        let checker = ValidationChecker::new(&manager);
85
86        let report = checker.validate();
87        assert!(report.is_ok());
88
89        // Clean up
90        let _ = std::fs::remove_file(db_path);
91    }
92}