use super::*;
#[test]
fn scope_from_user_flag() {
assert_eq!(Scope::from_user_flag(true), Scope::User);
assert_eq!(Scope::from_user_flag(false), Scope::System);
}
#[test]
fn scope_display_is_stable() {
assert_eq!(Scope::System.to_string(), "system");
assert_eq!(Scope::User.to_string(), "user");
}
#[test]
fn elevation_error_matches_documented_wording() {
let err = require_elevation("install").unwrap_err();
let msg = err.to_string();
assert!(
msg.contains("requires root"),
"elevation error must say what is required, got: {msg}"
);
assert!(
msg.contains("--user"),
"elevation error must offer the user-scope escape hatch, got: {msg}"
);
assert!(
msg.starts_with("service install requires root"),
"elevation error must name the verb first, got: {msg}"
);
}
#[test]
fn install_spec_is_comparable() {
let a = InstallSpec {
scope: Scope::System,
service_user: Some("all-smi".to_string()),
start_now: true,
force: false,
};
let b = a.clone();
assert_eq!(a, b);
}
#[test]
fn default_status_is_not_installed() {
let s = ServiceStatus::default();
assert!(!s.installed);
assert!(!s.running);
assert_eq!(s.enabled, None);
assert_eq!(s.pid, None);
}
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
#[test]
fn unsupported_platform_backend_points_at_the_canonical_unit() {
let err = backend().err().expect("no backend on this platform");
let msg = err.to_string();
assert!(matches!(err, ServiceError::NotSupported(_)));
assert!(msg.contains("packaging/systemd/all-smi.service"));
}
#[cfg(target_os = "linux")]
#[test]
fn linux_backend_resolves() {
assert!(backend().is_ok(), "Linux must always resolve a backend");
}
#[cfg(target_os = "macos")]
#[test]
fn macos_backend_resolves() {
assert!(backend().is_ok(), "macOS must resolve the launchd backend");
}
#[cfg(target_os = "windows")]
#[test]
fn windows_backend_resolves() {
assert!(backend().is_ok(), "Windows must resolve the SCM backend");
}
#[test]
fn user_scope_note_names_a_real_escape_hatch() {
let note = user_scope_persistence_note();
#[cfg(target_os = "macos")]
assert!(
note.contains("LaunchAgent") && note.contains("sudo all-smi service install"),
"macOS note must point at the system LaunchDaemon, got: {note}"
);
#[cfg(not(target_os = "macos"))]
assert!(
note.contains("enable-linger"),
"the systemd note must point at lingering, got: {note}"
);
}
#[test]
fn service_run_selects_no_scope() {
let action = crate::cli::ServiceAction::Run(crate::cli_service::ServiceRunArgs {});
assert!(!action.user_scope());
}
#[cfg(not(windows))]
#[test]
fn service_run_is_refused_off_windows() {
let code = run(&crate::cli::ServiceAction::Run(
crate::cli_service::ServiceRunArgs {},
));
assert_eq!(code, EXIT_ERROR);
}