Detect interfaces per platform; add macOS and single-interface support (closes #2)
Linux runs exactly as before when both bridge interfaces exist. When they do not, the lone default-route interface is monitored, and a single interface now draws a single UI pane instead of an empty second one. macOS is newly supported: a running VPN tunnel (utun) is monitored as the primary pane alongside the physical default-route interface, or the physical interface alone when no VPN is up. Detection lives in internal/netdetect: interface/route data types, pure selection logic keyed on OS name, and route parsers, all unit-tested on Linux for both platforms. Only the real route query and the per-platform TCP dial binding (source address on Linux, IP_BOUND_IF on macOS) are build-tagged. Ping argument construction is a pure, OS-keyed function. NewMonitor now takes a list of interfaces. Model: opus-4-8
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
@@ -10,27 +7,26 @@ import (
|
||||
// TestNewMonitor tests the creation of a new Monitor
|
||||
func TestNewMonitor(t *testing.T) {
|
||||
// Test that we can create a monitor without errors
|
||||
mon := NewMonitor("test0", "Test Interface A", "test1", "Test Interface B", "/tmp/test.log")
|
||||
mon := NewMonitor([]IfaceSpec{
|
||||
{Name: "test0", Label: "Test Interface A"},
|
||||
{Name: "test1", Label: "Test Interface B"},
|
||||
}, "/tmp/test.log")
|
||||
|
||||
if mon == nil {
|
||||
t.Fatal("NewMonitor returned nil")
|
||||
}
|
||||
|
||||
// Check interfaces
|
||||
if mon.interfaceA == nil {
|
||||
t.Fatal("interfaceA is nil")
|
||||
if len(mon.interfaces) != 2 {
|
||||
t.Fatalf("Expected 2 interfaces, got %d", len(mon.interfaces))
|
||||
}
|
||||
|
||||
if mon.interfaceB == nil {
|
||||
t.Fatal("interfaceB is nil")
|
||||
if mon.interfaces[0].Name != "test0" {
|
||||
t.Errorf("Expected interfaces[0].Name to be 'test0', got '%s'", mon.interfaces[0].Name)
|
||||
}
|
||||
|
||||
if mon.interfaceA.Name != "test0" {
|
||||
t.Errorf("Expected interfaceA.Name to be 'test0', got '%s'", mon.interfaceA.Name)
|
||||
}
|
||||
|
||||
if mon.interfaceB.Name != "test1" {
|
||||
t.Errorf("Expected interfaceB.Name to be 'test1', got '%s'", mon.interfaceB.Name)
|
||||
if mon.interfaces[1].Name != "test1" {
|
||||
t.Errorf("Expected interfaces[1].Name to be 'test1', got '%s'", mon.interfaces[1].Name)
|
||||
}
|
||||
|
||||
// Check default configuration
|
||||
@@ -56,9 +52,25 @@ func TestNewMonitor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewMonitorSingle verifies a monitor can be built with one interface.
|
||||
func TestNewMonitorSingle(t *testing.T) {
|
||||
mon := NewMonitor([]IfaceSpec{{Name: "eth0", Label: "default route"}}, "")
|
||||
|
||||
if len(mon.interfaces) != 1 {
|
||||
t.Fatalf("Expected 1 interface, got %d", len(mon.interfaces))
|
||||
}
|
||||
|
||||
if mon.interfaces[0].Name != "eth0" {
|
||||
t.Errorf("Expected interfaces[0].Name to be 'eth0', got '%s'", mon.interfaces[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAddHosts tests adding hosts to the monitor
|
||||
func TestAddHosts(t *testing.T) {
|
||||
mon := NewMonitor("test0", "Test A", "test1", "Test B", "")
|
||||
mon := NewMonitor([]IfaceSpec{
|
||||
{Name: "test0", Label: "Test A"},
|
||||
{Name: "test1", Label: "Test B"},
|
||||
}, "")
|
||||
|
||||
// Test adding reachability hosts
|
||||
mon.AddReachabilityHost("8.8.8.8")
|
||||
|
||||
Reference in New Issue
Block a user