#[derive(Debug, Clone)]
pub struct DetectedSystemResource {
pub resource_id: String,
pub display_name: String,
pub category: String,
pub size: u64,
pub description: String,
pub item_count: Option<u64>,
}
#[derive(Debug)]
pub enum SystemCleanResult {
Success {
resource: DetectedSystemResource,
freed_bytes: u64,
},
Failed {
resource: DetectedSystemResource,
error: String,
},
Skipped {
resource: DetectedSystemResource,
reason: String,
},
}
pub trait SystemCleaner: Send + Sync {
fn id(&self) -> &'static str;
fn display_name(&self) -> &'static str;
fn is_available(&self) -> bool;
fn detect(&self) -> Vec<DetectedSystemResource>;
fn clean(&self, resource: &DetectedSystemResource, dry_run: bool) -> SystemCleanResult;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detected_system_resource_creation() {
let resource = DetectedSystemResource {
resource_id: "test-resource".to_string(),
display_name: "Test Resource".to_string(),
category: "test".to_string(),
size: 1024,
description: "A test resource".to_string(),
item_count: Some(5),
};
assert_eq!(resource.resource_id, "test-resource");
assert_eq!(resource.display_name, "Test Resource");
assert_eq!(resource.category, "test");
assert_eq!(resource.size, 1024);
assert_eq!(resource.description, "A test resource");
assert_eq!(resource.item_count, Some(5));
}
#[test]
fn test_system_clean_result_variants() {
let resource = DetectedSystemResource {
resource_id: "test".to_string(),
display_name: "Test".to_string(),
category: "test".to_string(),
size: 100,
description: "test".to_string(),
item_count: None,
};
let _success = SystemCleanResult::Success {
resource: resource.clone(),
freed_bytes: 100,
};
let _failed = SystemCleanResult::Failed {
resource: resource.clone(),
error: "error".to_string(),
};
let _skipped = SystemCleanResult::Skipped {
resource,
reason: "reason".to_string(),
};
}
}