Add the Config view: edit and save the settings, applied without a restart

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 23:31:13 +02:00
co-authored by Claude Sonnet 5.5
parent 0ccd02b3c5
commit a4ec9ad71e
25 changed files with 1168 additions and 54 deletions
+36
View File
@@ -46,3 +46,39 @@ func TestSetSeasonMonitoredUnknownSeason(t *testing.T) {
t.Error("want error")
}
}
func TestReconfigureSwitchesInstanceAndKey(t *testing.T) {
var gotKey, gotHost string
mk := func(host string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotKey, gotHost = r.Header.Get("X-Api-Key"), host
io.WriteString(w, `{"version":"1"}`)
}))
}
a, b := mk("a"), mk("b")
defer a.Close()
defer b.Close()
c := NewClient(a.URL, "key-a")
var out struct{ Version string }
if err := c.Do(context.Background(), http.MethodGet, "system/status", nil, nil, &out); err != nil || gotHost != "a" || gotKey != "key-a" {
t.Fatalf("before: host=%q key=%q err=%v", gotHost, gotKey, err)
}
c.Reconfigure(b.URL+"/", "key-b") // a trailing slash is trimmed like in NewClient
if err := c.Do(context.Background(), http.MethodGet, "system/status", nil, nil, &out); err != nil || gotHost != "b" || gotKey != "key-b" {
t.Fatalf("after: host=%q key=%q err=%v", gotHost, gotKey, err)
}
// Used from many goroutines while being changed (run with -race to see it matter).
done := make(chan bool)
go func() {
for i := 0; i < 50; i++ {
c.Reconfigure(a.URL, "k")
c.Reconfigure(b.URL, "k")
}
done <- true
}()
for i := 0; i < 50; i++ {
_ = c.Do(context.Background(), http.MethodGet, "system/status", nil, nil, &out)
}
<-done
}