36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package web
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/sysfacts"
|
|
)
|
|
|
|
// R-1247: the operator's "Upload line" cell is judged on the last SUCCESSFUL test, never on the attempt time — an
|
|
// attempt is not a result.
|
|
// RED-PROOF: judge staleness on last_attempt_at → the 20-day-old success with a fresh failed attempt reads green → fails.
|
|
func TestLineTestCell(t *testing.T) {
|
|
now := time.Date(2026, 10, 24, 12, 0, 0, 0, time.UTC)
|
|
cases := []struct {
|
|
name string
|
|
lt *sysfacts.LineTest
|
|
text string
|
|
class string
|
|
}{
|
|
{"no stanza", nil, "—", ""},
|
|
{"never tried", &sysfacts.LineTest{Schedule: "weekly"}, "not yet", ""},
|
|
{"tried, never measured", &sysfacts.LineTest{Schedule: "weekly", LastAttemptAt: "2026-10-24T10:00:00Z", LastError: "iperf3 server busy"}, "not measured", "warn"},
|
|
{"fresh", &sysfacts.LineTest{Schedule: "weekly", LastOKAt: "2026-10-24T06:31:00Z", Mbps: 90.7}, "90.7 Mbit/s", ""},
|
|
{"old success, fresh failed attempt", &sysfacts.LineTest{Schedule: "weekly", LastOKAt: "2026-10-04T06:31:00Z", Mbps: 90.7,
|
|
LastAttemptAt: "2026-10-24T10:00:00Z", LastError: "connect: timeout"}, "90.7 Mbit/s", "warn"},
|
|
}
|
|
for _, c := range cases {
|
|
got := lineTestCell(c.lt, now)
|
|
if !strings.HasPrefix(got.Text, c.text) || got.Class != c.class {
|
|
t.Errorf("%s: cell = %+v, want text %q class %q", c.name, got, c.text, c.class)
|
|
}
|
|
}
|
|
}
|