added FIP Cooldown before start

This commit is contained in:
ayurishchev committed 2026-08-24 10:29:08 +03:00
1 parent 291eea3eb8
commit f22ad569b6
36 files changed
+1182 -25

No files matched your search

+55
View File
@@ -175,6 +175,61 @@ func TestIPsClear(t *testing.T) {
}
}
func TestSettingsGetAndPut(t *testing.T) {
fake, caURL := newFakeControlAPI(t)
ts := newTestServer(t, caURL)
page := get(t, ts, "/settings")
if !strings.Contains(page, `value="0"`) {
t.Fatalf("expected default 0 in the form, got:\n%s", page)
}
body := postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"15"}})
if !strings.Contains(body, `value="15"`) {
t.Fatalf("expected updated value 15 in re-rendered form, got:\n%s", body)
}
if fake.fipSettleSeconds != 15 {
t.Fatalf("expected fake control-api settings updated, got %d", fake.fipSettleSeconds)
}
// A control-api validation error (negative value here) surfaces via
// the banner, not a crash.
body = postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"-1"}})
if !strings.Contains(body, "alert-warning") {
t.Fatalf("expected client error banner for invalid value, got:\n%s", body)
}
// A non-numeric value is caught by the dashboard itself before it ever
// reaches control-api.
body = postForm(t, ts, "PUT", "/settings", map[string][]string{"fip_settle_seconds": {"not-a-number"}})
if !strings.Contains(body, "alert-warning") {
t.Fatalf("expected client error banner for non-numeric value, got:\n%s", body)
}
}
func TestIPsPageShowsSettleBadge(t *testing.T) {
fake, caURL := newFakeControlAPI(t)
now := time.Now()
fake.fipSettleSeconds = 60
fake.ips = []ipQueueItem{
{IPAddress: "1.1.1.1", State: "awaiting_self_check", FIPAssociatedAt: &now, UpdatedAt: now, CreatedAt: now},
}
ts := newTestServer(t, caURL)
body := get(t, ts, "/ips")
if !strings.Contains(body, "прогрев FIP") {
t.Fatalf("expected settle badge for a freshly-associated ip within the pause, got:\n%s", body)
}
// Once fip_settle_seconds is 0, the same row falls back to the plain
// state pill.
fake.fipSettleSeconds = 0
body = get(t, ts, "/ips")
if strings.Contains(body, "прогрев FIP") {
t.Fatalf("expected no settle badge once fip_settle_seconds is 0, got:\n%s", body)
}
}
func TestValidatorsCRUD(t *testing.T) {
_, caURL := newFakeControlAPI(t)
ts := newTestServer(t, caURL)