Files
rtnetmon/internal/monitor/styles_test.go
T
sneak ef3c373a12 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
2026-09-21 06:53:39 +00:00

103 lines
2.0 KiB
Go

package monitor
import (
"testing"
tcell "github.com/gdamore/tcell/v2"
)
// TestMeterColorForValue tests the MeterColorForValue function
func TestMeterColorForValue(t *testing.T) {
tests := []struct {
name string
value int
maxValue int
reverse bool
wantColor tcell.Style
}{
// Reverse mode tests (low is good, high is bad)
{
name: "reverse mode: 0% (best)",
value: 0,
maxValue: 10,
reverse: true,
wantColor: CBrightGreen,
},
{
name: "reverse mode: 10% (good)",
value: 1,
maxValue: 10,
reverse: true,
wantColor: CBrightGreen,
},
{
name: "reverse mode: 50% (medium)",
value: 5,
maxValue: 10,
reverse: true,
wantColor: CYellow,
},
{
name: "reverse mode: 90% (bad)",
value: 9,
maxValue: 10,
reverse: true,
wantColor: CRed,
},
{
name: "reverse mode: 100% (worst)",
value: 10,
maxValue: 10,
reverse: true,
wantColor: CRed,
},
// Normal mode tests (high is good, low is bad)
{
name: "normal mode: 0% (worst)",
value: 0,
maxValue: 10,
reverse: false,
wantColor: CRed,
},
{
name: "normal mode: 10% (bad)",
value: 1,
maxValue: 10,
reverse: false,
wantColor: CRed,
},
{
name: "normal mode: 50% (medium)",
value: 5,
maxValue: 10,
reverse: false,
wantColor: CYellow,
},
{
name: "normal mode: 90% (good)",
value: 9,
maxValue: 10,
reverse: false,
wantColor: CBrightGreen,
},
{
name: "normal mode: 100% (best)",
value: 10,
maxValue: 10,
reverse: false,
wantColor: CBrightGreen,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := MeterColorForValue(tt.value, tt.maxValue, tt.reverse)
if got != tt.wantColor {
t.Errorf("MeterColorForValue(%d, %d, %v) = %v, want %v",
tt.value, tt.maxValue, tt.reverse, got, tt.wantColor)
}
})
}
}