From b856945da8b2ef27b80f6e2ee291dbcfb4427aee Mon Sep 17 00:00:00 2001 From: Razvan Dimescu Date: Wed, 8 Apr 2026 15:24:50 +0300 Subject: [PATCH] test: add windows_backup_filters_loopback unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PR description mentioned this test but it was missing from the diff, leaving backup_has_real_upstream_windows untested. Mirrors the shape of macos_backup_real_upstream_detection: empty map → false, all-loopback (127.0.0.1, ::1, 0.0.0.0) → false, one real entry alongside loopback → true. Also relax the cfg gate on backup_has_real_upstream_windows from cfg(windows) to cfg(any(windows, test)) so the test compiles cross-platform, matching how backup_has_real_upstream_macos and the resolv_conf helpers are gated. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/system_dns.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/system_dns.rs b/src/system_dns.rs index dc0a0b1..098e69a 100644 --- a/src/system_dns.rs +++ b/src/system_dns.rs @@ -547,7 +547,7 @@ fn enable_dnscache() { } /// True if the backup map has at least one real upstream (non-loopback, non-stub). -#[cfg(windows)] +#[cfg(any(windows, test))] fn backup_has_real_upstream_windows( interfaces: &std::collections::HashMap, ) -> bool { @@ -1560,6 +1560,42 @@ Wireless LAN adapter Wi-Fi: assert!(backup_has_real_upstream_macos(&map)); } + #[test] + fn windows_backup_filters_loopback() { + use std::collections::HashMap; + let mut map: HashMap = HashMap::new(); + + // Empty backup → no real upstream + assert!(!backup_has_real_upstream_windows(&map)); + + // All-loopback backup → still no real upstream (the bug case) + map.insert( + "Wi-Fi".into(), + WindowsInterfaceDns { + dhcp: false, + servers: vec!["127.0.0.1".into()], + }, + ); + map.insert( + "Ethernet".into(), + WindowsInterfaceDns { + dhcp: false, + servers: vec!["::1".into(), "0.0.0.0".into()], + }, + ); + assert!(!backup_has_real_upstream_windows(&map)); + + // One real entry alongside loopback → useful + map.insert( + "Ethernet 2".into(), + WindowsInterfaceDns { + dhcp: false, + servers: vec!["192.168.1.1".into()], + }, + ); + assert!(backup_has_real_upstream_windows(&map)); + } + #[test] fn resolv_conf_real_upstream_detection() { let real = "nameserver 192.168.1.1\nsearch lan\n";