Files
nixos-router/pkgs/router-webui/sensors_test.go
T
nilsandClaude Sonnet 5.5 a36cebc827 Add dynamic DNS and show the running kernel on the overview
router.ddns keeps provider records on the uplink's addresses with ddclient,
run by a timer and by a watcher that starts it when an address changes. The
Dynamic DNS page edits it; the secret is a private file on the router. The
overview shows the running kernel and says when the current system boots a
different one. PLAN.md records why the A/B image approach was not pursued.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
2026-10-30 13:35:57 +01:00

70 lines
2.2 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)
}
}
func TestPendingKernel(t *testing.T) {
img := "/nix/store/abc123-linux-6.12.5/bzImage"
for running, want := range map[string]string{"6.12.5": "", "6.12.5-zen1": "", "6.12.4": "6.12.5", "": ""} {
if got := pendingKernel(running, img); got != want {
t.Errorf("running %q: %q, want %q", running, got, want)
}
}
if got := pendingKernel("6.12.4", "/boot/vmlinuz"); got != "" {
t.Errorf("an unknown path gave %q", got)
}
if k := systemStatus().Kernel; k == "" {
t.Skip("no /proc/sys/kernel/osrelease")
}
}