camel_component_exec/
bundle.rs1use std::sync::Arc;
7
8use camel_component_api::{CamelError, ComponentBundle, ComponentRegistrar};
9
10use crate::ExecComponent;
11use crate::config::ExecGlobalConfig;
12
13#[derive(Debug)]
15pub struct ExecBundle {
16 pub(crate) config: ExecGlobalConfig,
17}
18
19impl ExecBundle {
20 pub fn config(&self) -> &ExecGlobalConfig {
22 &self.config
23 }
24}
25
26impl ComponentBundle for ExecBundle {
27 fn config_key() -> &'static str {
28 "exec"
29 }
30
31 fn from_toml(value: toml::Value) -> Result<Self, CamelError> {
32 let mut config: ExecGlobalConfig = value
33 .try_into()
34 .map_err(|e: toml::de::Error| CamelError::Config(e.to_string()))?;
35 config.validate(&std::env::current_dir()?)?;
37 Ok(Self { config })
38 }
39
40 fn register_all(self, ctx: &mut dyn ComponentRegistrar) {
41 let component = ExecComponent::new(self.config);
42 ctx.register_component_dyn(Arc::new(component));
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::ExecBundle;
49 use camel_component_api::ComponentBundle;
50
51 #[test]
52 fn from_toml_fails_when_no_profiles() {
53 let v: toml::Value = toml::from_str("workspace_root = \".\"\n").unwrap();
54 let err = ExecBundle::from_toml(v).unwrap_err();
55 assert!(err.to_string().contains("no profiles"));
56 }
57
58 #[test]
59 fn config_key_is_exec() {
60 assert_eq!(ExecBundle::config_key(), "exec");
61 }
62}