diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f59e274..7884549 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,17 @@ jobs: - name: audit run: cargo install cargo-audit && cargo audit + check-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: clippy + run: cargo clippy -- -D warnings + - name: test + run: cargo test + check-windows: runs-on: windows-latest steps: diff --git a/src/system_dns.rs b/src/system_dns.rs index 25ab11e..8709e0d 100644 --- a/src/system_dns.rs +++ b/src/system_dns.rs @@ -903,6 +903,7 @@ pub fn uninstall_service() -> Result<(), String> { /// Restart the service (kill process, launchd/systemd auto-restarts with new binary). pub fn restart_service() -> Result<(), String> { + #[cfg(any(target_os = "macos", target_os = "linux"))] let exe_path = std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?; @@ -969,6 +970,7 @@ pub fn service_status() -> Result<(), String> { } } +#[cfg(any(target_os = "macos", target_os = "linux"))] fn replace_exe_path(service: &str) -> Result { let exe_path = std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?; @@ -1411,6 +1413,25 @@ Wireless LAN adapter Wi-Fi: ); } + #[test] + #[cfg(any(target_os = "macos", target_os = "linux"))] + fn replace_exe_path_substitutes_template() { + let plist = include_str!("../com.numa.dns.plist"); + let unit = include_str!("../numa.service"); + + assert!(plist.contains("{{exe_path}}"), "plist missing placeholder"); + assert!( + unit.contains("{{exe_path}}"), + "unit file missing placeholder" + ); + + let result = replace_exe_path(plist).expect("replace_exe_path failed for plist"); + assert!(!result.contains("{{exe_path}}")); + + let result = replace_exe_path(unit).expect("replace_exe_path failed for unit"); + assert!(!result.contains("{{exe_path}}")); + } + #[test] fn parse_ipconfig_skips_disconnected() { let sample = "\