635c33d381
gates / gates (push) Successful in 31s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package web
|
|
|
|
import (
|
|
"net/url"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/nightchain"
|
|
)
|
|
|
|
// R-871 / `09` decision 110 — the missed-backup banner through the REAL pages (ServeHTTP → executeTemplate) and the
|
|
// REAL dismiss route. The rule itself is pinned in internal/nightchain/banner_test.go.
|
|
// COMPANION RED-PROOF: remove `s.addMissedBackupBanner(data, r)` from executeTemplate → "not shown on /launcher".
|
|
|
|
const missedBannerID = `id="missed-backup-banner"`
|
|
|
|
func missedServer(t *testing.T, lastDump time.Time) (*Server, *nightchain.Ledger) {
|
|
t.Helper()
|
|
s := newDashboardServer(t, time.Time{})
|
|
l, err := nightchain.Open(filepath.Join(t.TempDir(), "night-ledger.json"), time.Now().Add(-10*24*time.Hour))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !lastDump.IsZero() {
|
|
l.MarkDBDumpOK(lastDump)
|
|
}
|
|
s.SetMissedBackupBanner(l, nil)
|
|
return s, l
|
|
}
|
|
|
|
func TestR871_BannerShownThenClosedUntilTheNextMiss(t *testing.T) {
|
|
s, l := missedServer(t, time.Now().Add(-3*24*time.Hour))
|
|
body := getPage(t, s, "/launcher").Body.String()
|
|
if !strings.Contains(body, missedBannerID) {
|
|
t.Fatal("not shown on /launcher although the last backup is 3 days old")
|
|
}
|
|
if !strings.Contains(body, "A legutóbbi mentés 3 nappal ezelőtt készült.") || !strings.Contains(body, `href="/backups#window_start"`) {
|
|
t.Fatalf("the banner lacks its sentence or its button:\n%s", body[strings.Index(body, missedBannerID):][:600])
|
|
}
|
|
rec := postForm(t, s, "/backups/missed-banner/dismiss", url.Values{"back": {"/launcher"}})
|
|
if rec.Code/100 != 3 {
|
|
t.Fatalf("dismiss = %d", rec.Code)
|
|
}
|
|
if strings.Contains(getPage(t, s, "/launcher").Body.String(), missedBannerID) {
|
|
t.Fatal("still shown after the household closed it")
|
|
}
|
|
if _, _, _, dismissed, _ := l.Snapshot(); dismissed.IsZero() {
|
|
t.Fatal("the dismissal was not recorded in the ledger (it would not survive a restart)")
|
|
}
|
|
}
|
|
|
|
func TestR871_BannerNotShownAfterASuccessfulNight(t *testing.T) {
|
|
s, _ := missedServer(t, time.Now().Add(-2*time.Hour))
|
|
if strings.Contains(getPage(t, s, "/launcher").Body.String(), missedBannerID) {
|
|
t.Fatal("shown although the last backup is 2 hours old")
|
|
}
|
|
}
|