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

81 lines
3.7 KiB
Go

package web
import (
"html"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/upwatch"
)
// The upload watch's household line: qBittorrent's page says the limit while the BOX owns it — in the reader's
// language — and says nothing when the household owns it (the view then carries 0), when no view is wired, or on
// another app's page.
// RED-PROOF: drop the `.QBLimitNote` card from app_shell.html → the first case fails; drop the slug check in the
// handler → crafty's page carries the line → fails.
func TestUpwatch_QBLimitLineOnQBittorrentsPageOnly(t *testing.T) {
s, _ := credsHarness(t)
sd := filepath.Join(s.cfg.Paths.StacksDir, "qbittorrent")
if err := os.MkdirAll(sd, 0o755); err != nil {
t.Fatal(err)
}
os.WriteFile(filepath.Join(sd, ".felhom.yml"), []byte("display_name: qBittorrent\nslug: qbittorrent\n"), 0o644)
os.WriteFile(filepath.Join(sd, "docker-compose.yml"), []byte("services: {}\n"), 0o644)
os.WriteFile(filepath.Join(sd, "app.yaml"), []byte("deployed: true\n"), 0o644)
_ = s.stackMgr.ScanStacks()
s.loadTemplates()
render := func(app, lang string) string {
rr := httptest.NewRecorder()
s.appPageHandler(rr, httptest.NewRequest("GET", "/apps/"+app+"?lang="+lang, nil), app, "")
return html.UnescapeString(rr.Body.String())
}
view := upwatch.View{LineMbps: 100, LineKnown: true, QBLimitBps: 6249472}
s.SetUpwatchView(func() upwatch.View { return view })
hu, en := asciiFold(render("qbittorrent", "hu")), render("qbittorrent", "en")
if !strings.Contains(hu, "data-qb-limit") || !strings.Contains(hu, "legfeljebb 50 Mbit/s") || !strings.Contains(hu, "atallithatod") {
t.Fatalf("the Hungarian qBittorrent page lacks the limit line")
}
if !strings.Contains(en, "uploads at most 50 Mbit/s") {
t.Fatalf("the English qBittorrent page lacks the limit line")
}
if strings.Contains(render("crafty", "hu"), "data-qb-limit") {
t.Fatal("another app's page carries qBittorrent's limit line")
}
view.QBLimitBps = 0 // the household owns it
if strings.Contains(render("qbittorrent", "hu"), "data-qb-limit") {
t.Fatal("a household-owned limit is described as the box's")
}
s.upwatchView = nil
if strings.Contains(render("qbittorrent", "hu"), "data-qb-limit") {
t.Fatal("no view wired, yet a line")
}
}
// The system page's upload line names its source: the weekly test („heti sebességméréssel") or the off-site push's floor
// („legalább … az éjszakai távoli mentésből"), in the reader's language.
// RED-PROOF: drop `data["UplinkTested"]` in systemPageData → the tested case reads „legalább" → fails.
func TestUpwatch_SystemPageNamesTheLinesSource(t *testing.T) {
s, _ := credsHarness(t)
s.loadTemplates()
render := func(lang string) string {
rr := httptest.NewRecorder()
s.settingsHandler(rr, httptest.NewRequest("GET", "/settings?lang="+lang, nil))
return asciiFold(html.UnescapeString(rr.Body.String()))
}
view := upwatch.View{LineMbps: 90.7, LineKnown: true, LineTested: true}
s.SetUpwatchView(func() upwatch.View { return view })
if hu := render("hu"); !strings.Contains(hu, "heti sebessegmeressel") || strings.Contains(hu, "legalabb <span") {
t.Fatal("tested line: the Hungarian system page does not say „heti sebességméréssel\"")
}
if en := render("en"); !strings.Contains(en, "Mbit/s (measured weekly)") {
t.Fatal("tested line: the English system page does not say „measured weekly\"")
}
view = upwatch.View{LineMbps: 10, LineKnown: true}
if hu := render("hu"); !strings.Contains(hu, "legalabb") || !strings.Contains(hu, "ejszakai tavoli mentesbol") || strings.Contains(hu, "heti sebessegmeressel") {
t.Fatal("push floor: the Hungarian system page does not say „legalább … az éjszakai távoli mentésből\"")
}
}