use proxywarden_lib::component_detection::DetectedSingBox; use proxywarden_lib::singbox_service::{ build_singbox_setup_status, singbox_service_xml, SINGBOX_SERVICE_LOG_DIR, }; use std::path::PathBuf; #[test] fn setup_status_reports_missing_items_when_singbox_is_absent() { let status = build_singbox_setup_status(None); assert!(!status.ready); assert_eq!(status.missing_count, 3); assert_eq!(status.items[0].id, "sing-box-binary"); assert!(status.items[0].details.contains("SagerNet/sing-box")); assert_eq!(status.items[1].id, "winsw-wrapper"); assert!(status.items[1].details.contains("winsw/winsw")); assert_eq!(status.items[2].id, "windows-service"); } #[test] fn setup_status_reports_ready_when_binary_wrapper_and_service_exist() { let detected = detected_singbox(true, true, true); let status = build_singbox_setup_status(Some(&detected)); assert!(status.ready); assert_eq!(status.missing_count, 0); assert!(status.items.iter().all(|item| item.installed)); assert_eq!(status.items[0].version, Some("1.11.0.0".to_string())); assert_eq!(status.items[1].version, Some("3.0.0.0".to_string())); assert_eq!(status.items[2].version, None); } #[test] fn winsw_disables_logs_and_targets_fixed_app_root_log_directory() { let xml = singbox_service_xml(); assert!(xml.contains("")); assert!(xml.contains(&format!("{SINGBOX_SERVICE_LOG_DIR}"))); assert_eq!( SINGBOX_SERVICE_LOG_DIR, r"%BASE%\..\..\.proxywarden-service-logs\sing-box" ); assert!(!xml.contains("ProgramData")); } fn detected_singbox(binary_exists: bool, wrapper_exists: bool, running: bool) -> DetectedSingBox { DetectedSingBox { install_dir: PathBuf::from(r"C:\Program Files\ProxyWarden\components\sing-box"), executable_path: PathBuf::from( r"C:\Program Files\ProxyWarden\components\sing-box\sing-box.exe", ), wrapper_path: PathBuf::from( r"C:\Program Files\ProxyWarden\components\sing-box\ProxyWardenSingBox.exe", ), binary_exists, wrapper_exists, running, service_name: "ProxyWardenSingBox".to_string(), version: Some("1.11.0.0".to_string()), wrapper_version: Some("3.0.0.0".to_string()), } }