test(cli): cover the DNS reset failure paths through the real code

The genuine-failure cases fed a fabricated error straight to
logIfaceLookupFailure, so they exercised only its own branching. A
restoration failure never reaches that helper, and no test reached the
enumeration classification in netInterface at all: discarding the
enumeration error, or downgrading an actual restoration failure to
debug, both kept the suite green.

The host boundaries of the reset path are now variables, in the style
the package already uses: the interface enumeration, the interface
lookup, the DNS setters and the NetworkManager restore. The tests stub
them, so a run changes no host DNS or NetworkManager state, and drive
the real netInterface and resetDNSForRunningIface to assert that a
failed enumeration keeps its cause and is not reported as a missing
interface, and that a failure to restore the saved static config or to
reset to DHCP on an interface that does exist stays at error level.
Both surviving mutations, and three more, now fail.
This commit is contained in:
Cuong Manh Le committed 2026-09-28 16:50:50 +07:00
1 parent 6eed09338d
commit 5410cc5f2b
3 files changed
+264 -49

No files matched your search

+5 -1
View File
@@ -1148,12 +1148,16 @@ func processLogAndCacheFlags(v *viper.Viper, cfg *ctrld.Config) {
// adapter, a torn down tether) is an expected outcome rather than a failure.
var errInterfaceNotFound = errors.New("interface not found")
// foreachInterface enumerates the host network interfaces. It is a variable so
// tests can make enumeration fail without depending on the host.
var foreachInterface = netmon.ForeachInterface
func netInterface(ifaceName string) (*net.Interface, error) {
if ifaceName == autoIface {
ifaceName = defaultIfaceName()
}
var iface *net.Interface
err := netmon.ForeachInterface(func(i netmon.Interface, prefixes []netip.Prefix) {
err := foreachInterface(func(i netmon.Interface, prefixes []netip.Prefix) {
if i.Name == ifaceName {
iface = i.Interface
}