use camel_component_api::{Component, ComponentBundle};
use camel_component_exec::{ExecBundle, ExecComponent, ExecError, ExecResult};
#[test]
fn scheme_is_exec() {
let component = ExecComponent::new(Default::default());
assert_eq!(component.scheme(), "exec");
}
#[test]
fn config_key_is_exec() {
assert_eq!(ExecBundle::config_key(), "exec");
}
#[test]
fn exec_error_match_forces_wildcard() {
let e = ExecError::Spawn(std::io::Error::other("test"));
let _desc = match &e {
ExecError::NotAllowlisted { .. } => "not allowlisted",
ExecError::ArgPolicyDenied { .. } => "arg denied",
ExecError::ShellRejected { .. } => "shell rejected",
ExecError::InvalidWorkDir { .. } => "invalid workdir",
ExecError::StdinTooLarge { .. } => "stdin too large",
ExecError::InvalidArgs(_) => "invalid args",
ExecError::Spawn(_) => "spawn",
_ => "future variant", };
assert!(!_desc.is_empty());
}
#[test]
fn exec_result_cannot_be_constructed_from_external_crate() {
let json = serde_json::json!({
"exit_code": 0,
"stdout": "dGVzdA==",
"stderr": "",
"stdout_truncated": false,
"stderr_truncated": false,
"timed_out": false,
"profile": "echo",
"duration_ms": 42,
});
let result: ExecResult = serde_json::from_value(json).expect("ExecResult deserialize");
assert_eq!(result.exit_code, Some(0));
assert_eq!(result.profile, "echo");
assert_eq!(result.duration_ms, 42);
}