fn test_EXCOV_015_apt_install_real_no_sudo() {
let executor = StepExecutor::new();
let packages = vec!["nonexistent_package_xyz".to_string()];
let result = executor.execute_apt_install("apt-test", &packages);
assert!(result.is_ok(), "Should return Ok, not panic");
}
#[test]
fn test_EXCOV_016_apt_install_dry_run_with_sudo() {
let executor = StepExecutor::with_config(ExecutorConfig {
dry_run: true,
use_sudo: true,
..Default::default()
});
let packages = vec!["vim".to_string()];
let result = executor.execute_apt_install("sudo-apt", &packages).unwrap();
assert!(result.success);
assert!(result.stdout.contains("[DRY-RUN]"));
assert!(result.stdout.contains("vim"));
}
#[test]
fn test_EXCOV_017_user_group_real() {
let executor = StepExecutor::new();
let result =
executor.execute_user_group("ug-test", "nonexistent_user_xyz", "nonexistent_group_xyz");
assert!(result.is_ok(), "Should return Ok, not panic");
let r = result.unwrap();
assert!(!r.success, "Should fail for non-existent user");
}
#[test]
fn test_EXCOV_018_user_group_dry_run_with_sudo() {
let executor = StepExecutor::with_config(ExecutorConfig {
dry_run: true,
use_sudo: true,
..Default::default()
});
let result = executor
.execute_user_group("sudo-ug", "deploy", "docker")
.unwrap();
assert!(result.success);
assert!(result.stdout.contains("[DRY-RUN]"));
}
#[test]
fn test_EXCOV_019_execute_step_apt_empty_packages() {
let toml = r#"
[installer]
name = "t"
version = "1.0.0"
[[step]]
id = "s"
name = "S"
action = "apt-install"
"#;
let spec = InstallerSpec::parse(toml).unwrap();
let executor = StepExecutor::new();
let result = executor.execute_step(&spec.step[0]).unwrap();
assert!(result.success, "Empty packages should succeed");
assert!(
result.stdout.contains("No packages"),
"Stdout: {}",
result.stdout
);
}
#[test]
fn test_EXCOV_020_script_bad_interpreter() {
let executor = StepExecutor::new();
let result = executor.execute_script("bad-interp", "nonexistent_interpreter_xyz", "echo hi");
assert!(result.is_err(), "Should error for missing interpreter");
}
#[test]
fn test_EXCOV_021_postcondition_service_active() {
let toml = r#"
[installer]
name = "t"
version = "1.0.0"
[[step]]
id = "s"
name = "S"
action = "script"
[step.script]
content = "true"
[step.postconditions]
service_active = "nonexistent_service_xyz"
"#;
let spec = InstallerSpec::parse(toml).unwrap();
let executor = StepExecutor::new();
let result = executor.execute_step(&spec.step[0]).unwrap();
assert!(!result.success);
let svc_check = result
.postcondition_results
.iter()
.find(|r| r.check_type == "service_active");
assert!(svc_check.is_some());
assert!(!svc_check.unwrap().passed);
}
#[test]
fn test_EXCOV_022_check_service_active_details() {
let executor = StepExecutor::new();
let result = executor.check_service_active("nonexistent_svc");
assert_eq!(result.check_type, "service_active");
assert!(
result.details.contains("not active") || result.details.contains("Failed"),
"Details: {}",
result.details
);
}
#[test]
fn test_EXCOV_023_duration_tracked() {
let executor = StepExecutor::new();
let result = executor
.execute_script("dur-test", "sh", "sleep 0.01")
.unwrap();
assert!(result.success);
assert!(
result.duration_ms > 0,
"Duration should be tracked: {}",
result.duration_ms
);
}
#[test]
fn test_EXCOV_024_default_implementation() {
let executor = StepExecutor::default();
let result = executor
.execute_script("default-test", "sh", "echo ok")
.unwrap();
assert!(result.success, "Default executor should work");
}
#[test]
fn test_EXCOV_025_debug_traits() {
let result = StepExecutionResult {
step_id: "test".to_string(),
success: true,
exit_code: Some(0),
stdout: "out".to_string(),
stderr: String::new(),
duration_ms: 100,
postcondition_results: vec![],
};
let debug_str = format!("{:?}", result);
assert!(debug_str.contains("test"), "Debug: {debug_str}");
let postcond = PostconditionResult {
check_type: "file_exists".to_string(),
passed: true,
details: "exists".to_string(),
};
let debug_str = format!("{:?}", postcond);
assert!(debug_str.contains("file_exists"), "Debug: {debug_str}");
let config = ExecutorConfig::default();
let debug_str = format!("{:?}", config);
assert!(debug_str.contains("dry_run"), "Debug: {debug_str}");
}
#[test]
fn test_EXCOV_026_clone_traits() {
let result = StepExecutionResult {
step_id: "test".to_string(),
success: true,
exit_code: Some(0),
stdout: "out".to_string(),
stderr: String::new(),
duration_ms: 100,
postcondition_results: vec![PostconditionResult {
check_type: "file_exists".to_string(),
passed: true,
details: "exists".to_string(),
}],
};
let cloned = result.clone();
assert_eq!(cloned.step_id, result.step_id);
assert_eq!(cloned.postcondition_results.len(), 1);
let config = ExecutorConfig {
dry_run: true,
use_sudo: true,
environment: {
let mut m = HashMap::new();
m.insert("K".to_string(), "V".to_string());
m
},
working_dir: Some("/tmp".to_string()),
timeout_secs: 60,
};
let cloned = config.clone();
assert_eq!(cloned.dry_run, config.dry_run);
assert_eq!(cloned.environment.len(), 1);
}