R-574: handler_debug.go literals classified; the 38 page-copy ones move to the bundle

39 Hungarian literals: 38 are debug-page copy (every writeDebugJSON message/error, rendered
into the result line by debug.html, plus the pre-0.83 agent notice rendered in the log
viewer) -> 30 debug.api.* keys (hu byte-equal, parity gate green; en added). One is PAYLOAD:
the 'Teszt esemény' text sent to the hub as the test event's message stays a literal. The
diagnostic dump carries no Hungarian. TestR574_DebugPageCopyFollowsTheLanguage pins hu bytes
and en rendering.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
2026-10-05 22:07:23 +02:00
parent 074ddda352
commit 391967bcf1
5 changed files with 200 additions and 38 deletions
+30
View File
@@ -1035,6 +1035,36 @@
"debug.verzio": "Version",
"debug.veszhelyzet_szimulacio": "Emergency simulation",
"debug.vezerlo": "Controller",
"debug.api.invalid_request": "Invalid request",
"debug.api.notifier_unconfigured": "Notifier is not configured",
"debug.api.event_sent": "Event sent (HTTP %d)",
"debug.api.backup_unconfigured": "Backup manager is not configured",
"debug.api.db_dump_started": "DB dump started",
"debug.api.crossdrive_none": "No installed app has a second-drive backup that could run",
"debug.api.crossdrive_started": "Cross-drive backup started; apps: %d",
"debug.api.not_wired": "Not wired",
"debug.api.proof_none_due": "No app is due — every latest backup is already checked",
"debug.api.proof_not_run": "The restore did not run — nothing was learned about the backup",
"debug.api.proof_ok": "The backup contains the app’s data",
"debug.api.proof_unknown": "Cannot be judged — the backup does not carry enough information",
"debug.api.proof_missing": "The backup is readable but does not contain the app’s data",
"debug.api.integrity_unreachable": "The repository cannot be reached — the check did not run",
"debug.api.integrity_ok": "The check completed without problems",
"debug.api.integrity_failed": "The check found an error in the repository",
"debug.api.hub_report_sent": "Hub report sent",
"debug.api.hub_reachable": "Hub reachable (HTTP %d, %dms)",
"debug.api.prefs_synced": "Preferences synchronised",
"debug.api.gitea_reachable": "Gitea reachable (HTTP %d, %dms)",
"debug.api.telemetry_collected": "Telemetry collected: apps %d, errors %d, warnings %d (%dms)",
"debug.api.selfupdate_unconfigured": "Self-update is not configured",
"debug.api.reset_confirm_invalid": "Invalid confirmation — type: RESET",
"debug.api.marker_write_failed": "Marker file write error: %v",
"debug.api.restarting_to_setup": "Restarting the controller into setup mode...",
"debug.api.agent_unconfigured": "The agent is not configured on this system.",
"debug.api.agent_logs_unsupported": "The agent’s log view becomes available after the agent’s next update.",
"debug.api.bundles_found": "Bundles found: %d",
"debug.api.no_temp_files": "No temp file to remove",
"debug.api.temp_files_removed": "Temp files removed: %d/%d",
"deploy.a_celalkalmazas_nem_fut": "The target app is not running",
"deploy.a_celalkalmazas_nincs_telepitve": "The target app is not installed",
"deploy.a_ket_jelszo_nem_egyezik": "The two passwords do not match:",
+30
View File
@@ -1030,6 +1030,36 @@
"debug.verzio": "Verzió",
"debug.veszhelyzet_szimulacio": "Vészhelyzet szimuláció",
"debug.vezerlo": "Vezérlő",
"debug.api.invalid_request": "Érvénytelen kérés",
"debug.api.notifier_unconfigured": "Notifier nincs konfigurálva",
"debug.api.event_sent": "Esemény elküldve (HTTP %d)",
"debug.api.backup_unconfigured": "Backup manager nincs konfigurálva",
"debug.api.db_dump_started": "DB dump elindítva",
"debug.api.crossdrive_none": "Nincs olyan telepített alkalmazás, amelynek 2. mentése futtatható lenne",
"debug.api.crossdrive_started": "Cross-drive mentés elindítva %d alkalmazásra",
"debug.api.not_wired": "Nem bekötött",
"debug.api.proof_none_due": "Nincs esedékes alkalmazás — minden legújabb mentés már ellenőrizve",
"debug.api.proof_not_run": "A visszaállítás nem futott le — a mentésről semmi nem derült ki",
"debug.api.proof_ok": "A mentés tartalmazza az alkalmazás adatait",
"debug.api.proof_unknown": "Nem megítélhető — a mentés nem hordoz elég információt",
"debug.api.proof_missing": "A mentés olvasható, de nem tartalmazza az alkalmazás adatait",
"debug.api.integrity_unreachable": "A tároló nem érhető el — az ellenőrzés nem futott le",
"debug.api.integrity_ok": "Az ellenőrzés rendben lezajlott",
"debug.api.integrity_failed": "Az ellenőrzés hibát talált a tárolóban",
"debug.api.hub_report_sent": "Hub jelentés elküldve",
"debug.api.hub_reachable": "Hub elérhető (HTTP %d, %dms)",
"debug.api.prefs_synced": "Preferenciák szinkronizálva",
"debug.api.gitea_reachable": "Gitea elérhető (HTTP %d, %dms)",
"debug.api.telemetry_collected": "Telemetria összegyűjtve: %d app, %d hiba, %d figyelmeztetés (%dms)",
"debug.api.selfupdate_unconfigured": "Self-update nincs konfigurálva",
"debug.api.reset_confirm_invalid": "Érvénytelen megerősítés — írja be: RESET",
"debug.api.marker_write_failed": "Marker fájl írási hiba: %v",
"debug.api.restarting_to_setup": "Controller újraindítása setup módba...",
"debug.api.agent_unconfigured": "Az ügynök nincs konfigurálva ezen a rendszeren.",
"debug.api.agent_logs_unsupported": "Az ügynök naplónézete az ügynök következő frissítése után érhető el.",
"debug.api.bundles_found": "%d csomag található",
"debug.api.no_temp_files": "Nincs eltávolítandó temp fájl",
"debug.api.temp_files_removed": "%d/%d temp fájl eltávolítva",
"deploy.a_celalkalmazas_nem_fut": "A célalkalmazás nem fut",
"deploy.a_celalkalmazas_nincs_telepitve": "A célalkalmazás nincs telepítve",
"deploy.a_ket_jelszo_nem_egyezik": "A két jelszó nem egyezik:",
+41 -38
View File
@@ -370,7 +370,7 @@ func (s *Server) debugTestEvent(w http.ResponseWriter, r *http.Request) {
Severity string `json:"severity"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Érvénytelen kérés", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.invalid_request"), nil)
return
}
if req.EventType == "" {
@@ -381,10 +381,13 @@ func (s *Server) debugTestEvent(w http.ResponseWriter, r *http.Request) {
}
if s.notifier == nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Notifier nincs konfigurálva", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.notifier_unconfigured"), nil)
return
}
// R-574: PAYLOAD, not page copy — this text travels to the hub as the test event's own message,
// so it stays a literal (every other Hungarian string in this file is debug-page copy and comes
// from the bundle, debug.api.*). The classification is written in TestR574_DebugPageCopyFollowsTheLanguage.
statusCode, err := s.notifier.PushTestEventSync(req.EventType, req.Severity,
fmt.Sprintf("Teszt esemény: %s (%s)", req.EventType, req.Severity))
if err != nil {
@@ -393,7 +396,7 @@ func (s *Server) debugTestEvent(w http.ResponseWriter, r *http.Request) {
})
return
}
writeDebugJSON(w, http.StatusOK, true, fmt.Sprintf("Esemény elküldve (HTTP %d)", statusCode),
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.event_sent", statusCode),
map[string]interface{}{"hub_status": statusCode})
}
@@ -410,7 +413,7 @@ func (s *Server) debugEventHistory(w http.ResponseWriter, r *http.Request) {
func (s *Server) debugTriggerDBDump(w http.ResponseWriter, r *http.Request) {
if s.backupMgr == nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Backup manager nincs konfigurálva", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.backup_unconfigured"), nil)
return
}
s.backupMgr.MarkManualRun() // R-182: a person pressed this, so its digest must not be collapsed
@@ -419,7 +422,7 @@ func (s *Server) debugTriggerDBDump(w http.ResponseWriter, r *http.Request) {
s.logger.Printf("[WARN] Debug DB dump failed: %v", err)
}
}()
writeDebugJSON(w, http.StatusOK, true, "DB dump elindítva", nil)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.db_dump_started"), nil)
}
// debugRunCrossDrive runs the Tier-2 (cross-drive) copy for every deployed HDD app (R-400).
@@ -435,14 +438,14 @@ func (s *Server) debugTriggerDBDump(w http.ResponseWriter, r *http.Request) {
// how a button reads as working while doing nothing — the class this whole row exists to close.
func (s *Server) debugRunCrossDrive(w http.ResponseWriter, r *http.Request) {
if s.backupMgr == nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Backup manager nincs konfigurálva", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.backup_unconfigured"), nil)
return
}
names := crossDriveTargets(s.stackMgr.GetStacks(), func(name string) bool {
return s.backupMgr.Tier2Info(name).IsHDDApp
})
if len(names) == 0 {
writeDebugJSON(w, http.StatusOK, true, "Nincs olyan telepített alkalmazás, amelynek 2. mentése futtatható lenne",
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.crossdrive_none"),
map[string]interface{}{"apps": names, "count": 0})
return
}
@@ -456,7 +459,7 @@ func (s *Server) debugRunCrossDrive(w http.ResponseWriter, r *http.Request) {
}
}(names)
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("Cross-drive mentés elindítva %d alkalmazásra", len(names)),
s.msg(r, "debug.api.crossdrive_started", len(names)),
map[string]interface{}{"apps": names, "count": len(names)})
}
@@ -498,7 +501,7 @@ func crossDriveTargets(all []stacks.Stack, isHDDApp func(name string) bool) []st
// that would reintroduce the hazard.
func (s *Server) debugRunOffsiteProof(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.RunOffsiteProof == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
res := s.debugCallbacks.RunOffsiteProof()
@@ -517,17 +520,17 @@ func (s *Server) debugRunOffsiteProof(w http.ResponseWriter, r *http.Request) {
case res.Skipped:
writeDebugJSON(w, http.StatusOK, true, "Kihagyva: "+res.SkipReason, data)
case res.NoSnapshot:
writeDebugJSON(w, http.StatusOK, true, "Nincs esedékes alkalmazás — minden legújabb mentés már ellenőrizve", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.proof_none_due"), data)
case res.Err != nil:
// NOT a verdict about the backup: the restore did not finish, so nothing was concluded.
data["error"] = res.Err.Error()
writeDebugJSON(w, http.StatusOK, true, "A visszaállítás nem futott le — a mentésről semmi nem derült ki", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.proof_not_run"), data)
case res.Judgement.Verdict == backup.UnitProofPass:
writeDebugJSON(w, http.StatusOK, true, "A mentés tartalmazza az alkalmazás adatait", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.proof_ok"), data)
case res.Judgement.Verdict == backup.UnitProofCannotJudge:
writeDebugJSON(w, http.StatusOK, true, "Nem megítélhető — a mentés nem hordoz elég információt", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.proof_unknown"), data)
default:
writeDebugJSON(w, http.StatusOK, false, "A mentés olvasható, de nem tartalmazza az alkalmazás adatait", data)
writeDebugJSON(w, http.StatusOK, false, s.msg(r, "debug.api.proof_missing"), data)
}
}
@@ -543,7 +546,7 @@ func (s *Server) debugRunOffsiteProof(w http.ResponseWriter, r *http.Request) {
// for it" is precisely the reasoning that would reintroduce the hazard.
func (s *Server) debugRunIntegrityCheck(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.RunIntegrityCheck == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
res := s.debugCallbacks.RunIntegrityCheck(true)
@@ -563,11 +566,11 @@ func (s *Server) debugRunIntegrityCheck(w http.ResponseWriter, r *http.Request)
writeDebugJSON(w, http.StatusOK, true, "Kihagyva: "+res.SkipReason, data)
case res.Unreachable:
// NOT reported as a failure: the store could not be opened, so nothing was concluded about it.
writeDebugJSON(w, http.StatusOK, true, "A tároló nem érhető el — az ellenőrzés nem futott le", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.integrity_unreachable"), data)
case res.OK:
writeDebugJSON(w, http.StatusOK, true, "Az ellenőrzés rendben lezajlott", data)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.integrity_ok"), data)
default:
writeDebugJSON(w, http.StatusOK, false, "Az ellenőrzés hibát talált a tárolóban", data)
writeDebugJSON(w, http.StatusOK, false, s.msg(r, "debug.api.integrity_failed"), data)
}
}
@@ -575,7 +578,7 @@ func (s *Server) debugRunIntegrityCheck(w http.ResponseWriter, r *http.Request)
func (s *Server) debugHubPush(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.TriggerHubReportPush == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
start := time.Now()
@@ -585,13 +588,13 @@ func (s *Server) debugHubPush(w http.ResponseWriter, r *http.Request) {
writeDebugJSON(w, http.StatusOK, false, s.errText(r, err), map[string]interface{}{"latency_ms": latency})
return
}
writeDebugJSON(w, http.StatusOK, true, "Hub jelentés elküldve",
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.hub_report_sent"),
map[string]interface{}{"latency_ms": latency})
}
func (s *Server) debugHubConnectivity(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.HubConnectivityTest == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
statusCode, latency, err := s.debugCallbacks.HubConnectivityTest()
@@ -604,12 +607,12 @@ func (s *Server) debugHubConnectivity(w http.ResponseWriter, r *http.Request) {
return
}
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("Hub elérhető (HTTP %d, %dms)", statusCode, latency), data)
s.msg(r, "debug.api.hub_reachable", statusCode, latency), data)
}
func (s *Server) debugPreferencesSync(w http.ResponseWriter, r *http.Request) {
if s.notifier == nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Notifier nincs konfigurálva", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.notifier_unconfigured"), nil)
return
}
prefs := s.settings.GetNotificationPrefs()
@@ -617,12 +620,12 @@ func (s *Server) debugPreferencesSync(w http.ResponseWriter, r *http.Request) {
writeDebugJSON(w, http.StatusOK, false, s.errText(r, err), nil)
return
}
writeDebugJSON(w, http.StatusOK, true, "Preferenciák szinkronizálva", nil)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.prefs_synced"), nil)
}
func (s *Server) debugGiteaConnectivity(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.GiteaConnectivityTest == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
statusCode, latency, err := s.debugCallbacks.GiteaConnectivityTest()
@@ -635,14 +638,14 @@ func (s *Server) debugGiteaConnectivity(w http.ResponseWriter, r *http.Request)
return
}
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("Gitea elérhető (HTTP %d, %dms)", statusCode, latency), data)
s.msg(r, "debug.api.gitea_reachable", statusCode, latency), data)
}
// ── Section: Telemetry testing ───────────────────────────────────────
func (s *Server) debugTelemetry(w http.ResponseWriter, r *http.Request) {
if s.debugCallbacks == nil || s.debugCallbacks.GetTelemetryPreview == nil {
writeDebugJSON(w, http.StatusNotImplemented, false, "Nem bekötött", nil)
writeDebugJSON(w, http.StatusNotImplemented, false, s.msg(r, "debug.api.not_wired"), nil)
return
}
start := time.Now()
@@ -661,7 +664,7 @@ func (s *Server) debugTelemetry(w http.ResponseWriter, r *http.Request) {
}
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("Telemetria összegyűjtve: %d app, %d hiba, %d figyelmeztetés (%dms)",
s.msg(r, "debug.api.telemetry_collected",
len(telemetry), totalErrors, totalWarnings, latency),
map[string]interface{}{
"latency_ms": latency,
@@ -676,7 +679,7 @@ func (s *Server) debugTelemetry(w http.ResponseWriter, r *http.Request) {
func (s *Server) debugSelfUpdateDryRun(w http.ResponseWriter, r *http.Request) {
if s.updater == nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Self-update nincs konfigurálva", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.selfupdate_unconfigured"), nil)
return
}
result := s.updater.DryRun()
@@ -690,11 +693,11 @@ func (s *Server) debugTriggerSetupWizard(w http.ResponseWriter, r *http.Request)
Confirm string `json:"confirm"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeDebugJSON(w, http.StatusBadRequest, false, "Érvénytelen kérés", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.invalid_request"), nil)
return
}
if req.Confirm != "RESET" {
writeDebugJSON(w, http.StatusBadRequest, false, "Érvénytelen megerősítés — írja be: RESET", nil)
writeDebugJSON(w, http.StatusBadRequest, false, s.msg(r, "debug.api.reset_confirm_invalid"), nil)
return
}
@@ -702,11 +705,11 @@ func (s *Server) debugTriggerSetupWizard(w http.ResponseWriter, r *http.Request)
markerPath := filepath.Join(s.cfg.Paths.DataDir, ".needs-setup")
if err := os.WriteFile(markerPath, []byte("debug-triggered\n"), 0644); err != nil {
writeDebugJSON(w, http.StatusInternalServerError, false,
fmt.Sprintf("Marker fájl írási hiba: %v", err), nil)
s.msg(r, "debug.api.marker_write_failed", err), nil)
return
}
writeDebugJSON(w, http.StatusOK, true, "Controller újraindítása setup módba...", nil)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.restarting_to_setup"), nil)
// Exit after response is sent so the container restarts into setup mode
go func() {
@@ -762,7 +765,7 @@ func (s *Server) debugAgentLogs(w http.ResponseWriter, r *http.Request) {
if fetch == nil {
client, err := s.agentClient()
if err != nil {
writeDebugJSON(w, http.StatusOK, false, "Az ügynök nincs konfigurálva ezen a rendszeren.", nil)
writeDebugJSON(w, http.StatusOK, false, s.msg(r, "debug.api.agent_unconfigured"), nil)
return
}
fetch = client.DebugLogs
@@ -775,7 +778,7 @@ func (s *Server) debugAgentLogs(w http.ResponseWriter, r *http.Request) {
if errors.As(err, &se) && se.Code == http.StatusNotFound {
writeDebugJSON(w, http.StatusOK, true, "", map[string]interface{}{
"unsupported": true,
"notice": "Az ügynök naplónézete az ügynök következő frissítése után érhető el.",
"notice": s.msg(r, "debug.api.agent_logs_unsupported"),
})
return
}
@@ -843,7 +846,7 @@ func (s *Server) debugAppExportBundles(w http.ResponseWriter, r *http.Request) {
bundles := appexport.ScanForBundles(drives)
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("%d csomag található", len(bundles)),
s.msg(r, "debug.api.bundles_found", len(bundles)),
map[string]interface{}{"bundles": bundles})
}
@@ -857,7 +860,7 @@ func (s *Server) debugAppExportCleanup(w http.ResponseWriter, r *http.Request) {
staleFiles := appexport.ScanForStaleTempFiles(drives)
if len(staleFiles) == 0 {
writeDebugJSON(w, http.StatusOK, true, "Nincs eltávolítandó temp fájl", nil)
writeDebugJSON(w, http.StatusOK, true, s.msg(r, "debug.api.no_temp_files"), nil)
return
}
@@ -872,5 +875,5 @@ func (s *Server) debugAppExportCleanup(w http.ResponseWriter, r *http.Request) {
}
writeDebugJSON(w, http.StatusOK, true,
fmt.Sprintf("%d/%d temp fájl eltávolítva", removed, len(staleFiles)), nil)
s.msg(r, "debug.api.temp_files_removed", removed, len(staleFiles)), nil)
}
@@ -0,0 +1,69 @@
package web
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/agentapi"
)
// R-574 — handler_debug.go's literals, classified once: 38 are PAGE COPY (every writeDebugJSON
// message/error, which debug.html prints into the result line, plus the pre-0.83 agent `notice`,
// which it prints into the log viewer) and were moved to the bundle (debug.api.*); ONE is PAYLOAD —
// the `Teszt esemény: %s (%s)` text handed to PushTestEventSync, which travels to the hub as the
// test event's own message — and stays a literal on purpose. The diagnostic dump carries no
// Hungarian.
//
// The consequence pinned here: the Hungarian page is byte-for-byte what it was (the parity gate
// proves the bundle text; this proves the handler reads it), and an English page is English.
// RED-PROOF (REPORT): put either producer back to its literal and the English rows fail.
func TestR574_DebugPageCopyFollowsTheLanguage(t *testing.T) {
type debugResp struct {
OK bool `json:"ok"`
Error string `json:"error"`
Data struct {
Notice string `json:"notice"`
} `json:"data"`
}
run := func(t *testing.T, lang string, call func(s *Server, w http.ResponseWriter, r *http.Request)) debugResp {
t.Helper()
s := testServer(t)
if s.settings == nil {
t.Fatal("testServer has no settings — the language cannot be set")
}
s.settings.SetConfigLanguage(lang)
w := httptest.NewRecorder()
call(s, w, httptest.NewRequest(http.MethodPost, "/api/debug/x", nil))
var resp debugResp
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v (%s)", err, w.Body.String())
}
return resp
}
dbDump := func(s *Server, w http.ResponseWriter, r *http.Request) {
s.backupMgr = nil
s.debugTriggerDBDump(w, r)
}
notice := func(s *Server, w http.ResponseWriter, r *http.Request) {
s.agentLogsFn = func(context.Context) (agentapi.AgentLogsResponse, error) {
return agentapi.AgentLogsResponse{}, &agentapi.StatusError{Path: "/debug/logs", Code: http.StatusNotFound}
}
s.debugAgentLogs(w, r)
}
if got := run(t, "hu", dbDump).Error; got != "Backup manager nincs konfigurálva" {
t.Errorf("hu error = %q — the Hungarian bytes moved", got)
}
if got := run(t, "en", dbDump).Error; got != "Backup manager is not configured" {
t.Errorf("en error = %q — the handler does not read the bundle", got)
}
if got := run(t, "hu", notice).Data.Notice; got != "Az ügynök naplónézete az ügynök következő frissítése után érhető el." {
t.Errorf("hu notice = %q — the Hungarian bytes moved", got)
}
if got := run(t, "en", notice).Data.Notice; got != "The agent’s log view becomes available after the agent’s next update." {
t.Errorf("en notice = %q — the handler does not read the bundle", got)
}
}