pub mod shell;
use klasp_core::{CheckConfig, CheckSource};
pub struct SourceRegistry {
sources: Vec<Box<dyn CheckSource>>,
}
impl SourceRegistry {
pub fn default_v1() -> Self {
let sources: Vec<Box<dyn CheckSource>> = vec![Box::new(shell::ShellSource::new())];
Self { sources }
}
pub fn find_for(&self, check: &CheckConfig) -> Option<&dyn CheckSource> {
self.sources
.iter()
.find(|s| s.supports_config(check))
.map(|b| b.as_ref())
}
}
impl Default for SourceRegistry {
fn default() -> Self {
Self::default_v1()
}
}
#[cfg(test)]
mod tests {
use klasp_core::{CheckConfig, CheckSourceConfig};
use super::*;
fn shell_check() -> CheckConfig {
CheckConfig {
name: "demo".into(),
triggers: vec![],
source: CheckSourceConfig::Shell {
command: "true".into(),
},
timeout_secs: None,
}
}
#[test]
fn registry_dispatches_shell_check_to_shell_source() {
let registry = SourceRegistry::default_v1();
let source = registry
.find_for(&shell_check())
.expect("shell source must claim shell config");
assert_eq!(source.source_id(), "shell");
}
}