package web import ( "strings" "testing" "time" "gitea.dooplex.hu/admin/felhom-hub/internal/monitor" ) // R-277(b): a small but non-empty off-site repo must not render as "0.0 GB" on the Offsite page — that // reading is how a healthy tier was reported to the operator as absent. func TestOffsiteRow_SmallRepoNotZeroGB(t *testing.T) { s, st := newRenderServer(t) s.SetOffsiteBox(func() (monitor.BoxSnapshot, bool) { return monitor.BoxSnapshot{CapacityBytes: 1 << 40, FillBand: "ok", OversubBand: "ok", FetchedAt: time.Now().UTC()}, true }) saveCfg(t, st, "tiny", `{"offsite":{"enabled":true,"type":"shared","quota_gb":500}}`) if err := st.SaveReport("tiny", []byte(`{"customer_id":"tiny","offsite":{"enabled":true,"repo_size_bytes":165888}}`)); err != nil { t.Fatal(err) } rows := s.offsiteCustomerRows() if len(rows) != 1 { t.Fatalf("want 1 row, got %d", len(rows)) } if rows[0].UsageStr == "0.0 GB" || rows[0].UsageStr != "162.0 KB" { t.Fatalf("162 KB repo rendered as %q, want \"162.0 KB\"", rows[0].UsageStr) } body := renderOffsite(t, s) if !strings.Contains(body, "162.0 KB") { t.Fatal("Offsite page must show the small repo's real size") } // Above 1 GB the unit stays GB (same as the quota column). if got := fmtBytesAuto(200 * gib); got != "200.0 GB" { t.Fatalf("200 GiB = %q, want 200.0 GB", got) } } // R-92: two PBS DR polls 50 MB apart read identically at 0.1 GB granularity; the page must show a value // that differs between them, so a small delta (a prune, a GC) is verifiable from the hub. func TestPBSDRPanel_ExactBytesShowsSmallDelta(t *testing.T) { render := func(used int64) string { s, _ := newRenderServer(t) s.SetPBSDRBox(func() (monitor.PBSBoxSnapshot, bool) { return monitor.PBSBoxSnapshot{ CapacityBytes: 40 * gib, UsedBytes: used, FillPercent: 20, FillBand: "ok", State: monitor.PBSStateOK, FetchedAt: time.Now().UTC(), }, true }) return pbsSection(renderOffsite(t, s)) } a := render(8 * gib) b := render(8*gib + 50_000_000) if !strings.Contains(a, "8 589 934 592 bytes") { t.Fatalf("PBS DR panel must show exact bytes:\n%s", a) } if !strings.Contains(b, "8 639 934 592 bytes") { t.Fatalf("PBS DR panel must show the +50 MB exact value:\n%s", b) } if fmtBytesExact(999) != "999 bytes" || fmtBytesExact(1000) != "1 000 bytes" { t.Fatalf("grouping wrong: %q %q", fmtBytesExact(999), fmtBytesExact(1000)) } }