test: add windows_backup_filters_loopback unit test

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) <noreply@anthropic.com>
This commit is contained in:
Razvan Dimescu
2026-04-08 15:24:50 +03:00
parent 34b1d0e6df
commit b856945da8

View File

@@ -547,7 +547,7 @@ fn enable_dnscache() {
} }
/// True if the backup map has at least one real upstream (non-loopback, non-stub). /// 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( fn backup_has_real_upstream_windows(
interfaces: &std::collections::HashMap<String, WindowsInterfaceDns>, interfaces: &std::collections::HashMap<String, WindowsInterfaceDns>,
) -> bool { ) -> bool {
@@ -1560,6 +1560,42 @@ Wireless LAN adapter Wi-Fi:
assert!(backup_has_real_upstream_macos(&map)); assert!(backup_has_real_upstream_macos(&map));
} }
#[test]
fn windows_backup_filters_loopback() {
use std::collections::HashMap;
let mut map: HashMap<String, WindowsInterfaceDns> = 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] #[test]
fn resolv_conf_real_upstream_detection() { fn resolv_conf_real_upstream_detection() {
let real = "nameserver 192.168.1.1\nsearch lan\n"; let real = "nameserver 192.168.1.1\nsearch lan\n";