Files
felhom-controller/controller/internal/web/r1270_not_started_test.go
T

41 lines
1.8 KiB
Go

package web
import (
"errors"
"io"
"log"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
"gitea.dooplex.hu/admin/felhom-controller/internal/util"
)
// R-1270 — a restore whose data is back but whose app did not start is recorded as NOT ok, with its own sentence
// alone (never „Visszaállítás sikertelen: …", never „…az alkalmazás újraindult."); any other error stays a failure.
// COMPANION RED-PROOF (REPORT.md): drop the errors.Is branch in endRestoreFailed → this fails on the „sikertelen" prefix
// and on NotStarted.
func TestR1270_TheRecordOfANotStartedRestore(t *testing.T) {
lg := log.New(io.Discard, "", 0)
cfg := &config.Config{}
cfg.Paths.DataDir = t.TempDir()
s := &Server{cfg: cfg, backupMgr: backup.NewManager(cfg, nil, lg), logger: lg}
s.backupMgr.BeginRestoreOp("restore", "tandoor")
s.endRestoreFailed("note.restore.unit_failed", util.MsgErrorf(backup.ErrRestoreNotStarted, "err.backup.restore_not_started", "tandoor"), "")
st := s.backupMgr.RestoreStatus()
if st.Last == nil || st.Last.OK || !st.Last.NotStarted {
t.Fatalf("a not-started restore is recorded not ok and not started: %+v", st.Last)
}
if strings.Contains(st.Last.Message, "sikertelen") || strings.Contains(st.Last.Message, "újraindult") || !strings.Contains(st.Last.Message, "még nem indult el") {
t.Fatalf("the household reads the not-started sentence alone: %q", st.Last.Message)
}
s.backupMgr.BeginRestoreOp("restore", "tandoor")
s.endRestoreFailed("note.restore.unit_failed", errors.New("boom"), "")
if st := s.backupMgr.RestoreStatus(); st.Last.OK || st.Last.NotStarted || !strings.Contains(st.Last.Message, "sikertelen") {
t.Fatalf("any other error stays a failure: %+v", st.Last)
}
}