The firewall page now manages zones (assign each LAN or tunnel, add and remove zones) and rules with zone, address and port on both sides plus the protocol. router.firewall.zones declares zones without members and rules take sourcePorts. The temperature chart draws every thermal zone and hwmon sensor; the overview defaults to 15 minutes, 1h stays an option. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadSensors(t *testing.T) {
|
|
root := t.TempDir()
|
|
write := func(path, content string) {
|
|
t.Helper()
|
|
p := filepath.Join(root, path)
|
|
os.MkdirAll(filepath.Dir(p), 0o755)
|
|
if err := os.WriteFile(p, []byte(content+"\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
write("thermal/thermal_zone0/type", "acpitz")
|
|
write("thermal/thermal_zone0/temp", "47000")
|
|
write("thermal/thermal_zone1/type", "x86_pkg_temp")
|
|
write("thermal/thermal_zone1/temp", "61000")
|
|
write("thermal/thermal_zone2/type", "broken")
|
|
write("thermal/thermal_zone2/temp", "0")
|
|
write("hwmon/hwmon3/name", "coretemp")
|
|
write("hwmon/hwmon3/temp1_input", "62000")
|
|
write("hwmon/hwmon3/temp1_label", "Package id 0")
|
|
write("hwmon/hwmon3/temp2_input", "58500")
|
|
write("hwmon/hwmon3/temp2_label", "Core 0")
|
|
write("hwmon/hwmon4/name", "nvme")
|
|
write("hwmon/hwmon4/temp1_input", "39000")
|
|
write("hwmon/hwmon5/name", "nvme")
|
|
write("hwmon/hwmon5/temp1_input", "41000")
|
|
|
|
got := readSensors(filepath.Join(root, "thermal"), filepath.Join(root, "hwmon"))
|
|
want := map[string]float64{
|
|
"acpitz": 47, "x86_pkg_temp": 61, "coretemp Package id 0": 62, "coretemp Core 0": 58.5,
|
|
"nvme temp1": 39, "nvme temp1 2": 41,
|
|
}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("sensors = %+v", got)
|
|
}
|
|
for _, s := range got {
|
|
if v, ok := want[s.Label]; !ok || v != s.Temp || s.Key != s.Label {
|
|
t.Errorf("unexpected %+v", s)
|
|
}
|
|
}
|
|
if h := hottest(got); h != 62 {
|
|
t.Errorf("hottest = %v", h)
|
|
}
|
|
if got := readSensors(filepath.Join(root, "none"), filepath.Join(root, "none")); len(got) != 0 || hottest(got) == hottest(got) {
|
|
t.Errorf("no sensors: %+v (hottest should be NaN)", got)
|
|
}
|
|
}
|