package monitor import ( "fmt" "testing" "gitea.dooplex.hu/admin/felhom-controller/internal/settings" ) // TestStorageWarningWireTextIsFrozen — localisation slice 2 (R-557), scenario S6. // // `HealthReport.Warnings` is ON THE WIRE: report/builder.go copies it into `health.warnings`, the hub // stores it and the operator reads it there. The rule for slice 2 is that nothing on the wire moves — // so these five sentences may NOT become bundle keys the way a page's copy does, however English the // household's dashboard is. // // The golden below was captured from this file at 736f54b49610, the base commit of v0.252.0, BEFORE // any conversion. It is the measurement, not a restatement of the code: a rewording, a re-punctuation // or a translation of any producer in checkStoragePaths fails here and prints both strings. // // What the DASHBOARD shows for these warnings follows the language by a different route — the kinds // beside them (WarnKind*, internal, never on the wire) plus the parameters, so the page can render its // own sentence without the wire text changing. See internal/web/alerts.go. func TestStorageWarningWireTextIsFrozen(t *testing.T) { // A path that cannot exist, so os.Stat fails deterministically on any machine. const absent = "/felhom-test-does-not-exist/adat" cases := []struct { name string in settings.StoragePath want []string kind []string }{ { name: "disconnected", in: settings.StoragePath{Path: "/mnt/hdd_1", Label: "Kulso HDD", Disconnected: true}, want: []string{"Meghajtó leválasztva: Kulso HDD (/mnt/hdd_1)"}, kind: []string{WarnKindStorageDisconnected}, }, { name: "unavailable", in: settings.StoragePath{Path: absent, Label: "Adat"}, want: []string{"Adattároló nem elérhető: " + absent}, kind: []string{WarnKindStorageUnavailable}, }, { name: "decommissioned is silent", in: settings.StoragePath{Path: absent, Decommissioned: true}, want: nil, kind: nil, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { _, warnings, kinds := checkStoragePaths([]settings.StoragePath{tc.in}) if len(warnings) != len(tc.want) { t.Fatalf("got %d warnings %q, want %d %q", len(warnings), warnings, len(tc.want), tc.want) } for i := range tc.want { if warnings[i] != tc.want[i] { t.Errorf("wire text moved:\n got %q\n want %q", warnings[i], tc.want[i]) } if kinds[i] != tc.kind[i] { t.Errorf("kind moved: got %q, want %q", kinds[i], tc.kind[i]) } } }) } } // TestStorageWarningFormatsAreFrozen pins the three producers the table above cannot reach on every // machine — they need a real mount point and a real 91 %-full disk, and faking either would test the // fake. It compares the CONSTANTS the producers use, so a translation fails here whatever the machine. // // The rendered form is compared too, not only the format string: a change from `%s` to `%v`, or a // verb reordered with an explicit index, leaves the format literal looking similar and the sentence // different. func TestStorageWarningFormatsAreFrozen(t *testing.T) { cases := []struct { name, got, want string }{ {"disconnected", fmt.Sprintf(warnFmtStorageDisconnected, "Kulso HDD", "/mnt/hdd_1"), "Meghajtó leválasztva: Kulso HDD (/mnt/hdd_1)"}, {"unavailable", fmt.Sprintf(warnFmtStorageUnavailable, "/mnt/adat"), "Adattároló nem elérhető: /mnt/adat"}, {"not separate", fmt.Sprintf(warnFmtStorageNotSeparate, "/mnt/adat"), "Az adattároló (/mnt/adat) nem külön meghajtón van — az adatok a rendszermeghajtóra íródnak"}, {"usage high", fmt.Sprintf(warnFmtStorageUsageHigh, "/mnt/adat", 91.4), "Adattároló használat magas: /mnt/adat (91%)"}, {"almost full", fmt.Sprintf(issueFmtStorageAlmostFull, "/mnt/adat", 96.0), "Adattároló majdnem megtelt: /mnt/adat (96%)"}, } for _, tc := range cases { if tc.got != tc.want { t.Errorf("%s: wire text moved (slice 2 may not translate a sentence the hub reads)\n"+ " got %q\n want %q", tc.name, tc.got, tc.want) } } }