Files
felhom-controller/controller/internal/api/selfrestart_test.go
T
admin f037be7a6a
gates / gates (push) Successful in 48s
R-970: the box's hub key opens no route; Data tab leftovers; R-1103: the install form's dead branches
R-970: /api/config, /api/config/hash, /api/config/apply removed (they read and replaced controller.yaml with
every secret, reachable with the box's own hub API key, unsigned; nothing called them). The hub-key Bearer
door on /api/selfupdate/ and /api/geo/ and the matching CSRF exemption are gone; the dashboard keeps using
those with a session. The route table is buildMux, so a test drives the real one.

Data tab: the export password field is autocomplete=new-password with a non-login name; the 2nd copy's
status rows that repeated the form are gone (the no-target reason moves into the form).

R-1103: app_fields.html loses its installed-only branches (no page serves them since R-1095); the tests
that rendered that dead path are retired, their rules asserted on the settings tab (R-694 moved there).

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-16 18:24:00 +02:00

44 lines
1.0 KiB
Go

package api
import (
"io"
"log"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
// newRestartTestRouter builds a minimal Router with a recording restart seam (so the
// process is never actually killed) and a config path seeded with `prior`.
func newRestartTestRouter(t *testing.T, prior []byte) (*Router, *int, string) {
t.Helper()
dir := t.TempDir()
path := filepath.Join(dir, "controller.yaml")
if prior != nil {
if err := os.WriteFile(path, prior, 0o600); err != nil {
t.Fatal(err)
}
}
calls := 0
r := &Router{configPath: path, logger: log.New(io.Discard, "", 0)}
r.restart = func() { calls++ }
return r, &calls, path
}
func TestSelfRestart_InvokesRestarter(t *testing.T) {
r, calls, _ := newRestartTestRouter(t, nil)
req := httptest.NewRequest(http.MethodPost, "/api/selfrestart", nil)
rec := httptest.NewRecorder()
r.selfRestart(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200", rec.Code)
}
if *calls != 1 {
t.Fatalf("restart called %d times, want 1", *calls)
}
}