use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct TestSection {
pub name: String,
pub enabled: bool,
pub timeout_seconds: u64,
pub dependencies: Vec<String>,
}
impl Default for TestSection {
fn default() -> Self {
Self {
name: "default".to_string(),
enabled: true,
timeout_seconds: 300, dependencies: Vec::new(),
}
}
}
pub struct SectionRunner {
sections: HashMap<String, TestSection>,
}
impl SectionRunner {
pub fn new() -> Self {
Self {
sections: HashMap::new(),
}
}
pub fn add_section(&mut self, section: TestSection) {
self.sections.insert(section.name.clone(), section);
}
pub fn enable_section(&mut self, name: &str) {
if let Some(section) = self.sections.get_mut(name) {
section.enabled = true;
}
}
pub fn disable_section(&mut self, name: &str) {
if let Some(section) = self.sections.get_mut(name) {
section.enabled = false;
}
}
pub fn run_section(&self, name: &str) -> Result<(), String> {
if let Some(section) = self.sections.get(name) {
if !section.enabled {
return Err(format!("Section '{name}' is disabled"));
}
for dep in §ion.dependencies {
if !self.sections.contains_key(dep) {
return Err(format!("Missing dependency '{dep}' for section '{name}'"));
}
}
println!("Running test section: {}", section.name);
Ok(())
} else {
Err(format!("Section '{name}' not found"))
}
}
pub fn list_sections(&self) -> Vec<&str> {
self.sections.keys().map(|s| s.as_str()).collect()
}
}
impl Default for SectionRunner {
fn default() -> Self {
Self::new()
}
}