use robin::config::RobinConfig;
use robin::tools::{check_environment, update_tools};
use serde_json::{Value, json};
use std::collections::HashMap;
fn config_with(scripts: &[(&str, Value)]) -> RobinConfig {
let mut map = HashMap::new();
for (name, script) in scripts {
map.insert((*name).to_string(), script.clone());
}
RobinConfig {
schema: None,
include: vec![],
scripts: map,
}
}
#[test]
fn check_environment_reports_nothing_for_toolless_config() {
let config = config_with(&[("hello", json!("echo hello world"))]);
let (passed, found, missing, duration) = check_environment(&config).unwrap();
assert!(passed);
assert_eq!(found, 0);
assert_eq!(missing, 0);
assert!(duration.as_secs_f32() >= 0.0);
}
#[test]
fn check_environment_probes_detected_tools() {
let config = config_with(&[("status", json!("git status"))]);
let (_passed, found, missing, _duration) = check_environment(&config).unwrap();
assert!(
found + missing >= 1,
"git should trigger at least one check"
);
}
#[test]
fn update_tools_is_a_noop_without_updatable_tools() {
let config = config_with(&[("hello", json!("echo hi")), ("status", json!("git status"))]);
let (success, updated) = update_tools(&config).unwrap();
assert!(success);
assert!(updated.is_empty(), "no updatable tools => nothing updated");
}