package main import ( "bytes" "strings" "testing" "time" "github.com/carlosframework/platform/internal/apperr" ) func TestPrintErrorGroups(t *testing.T) { now := time.Date(2026, 9, 7, 10, 0, 0, 0, time.UTC) var buf bytes.Buffer printErrorGroups(&buf, []apperr.Group{ {FP: "abc123", Source: "edge", Name: "500 POST /checkout", Count: 12, Last: now, Hosts: []string{"a.example"}, Releases: []string{"v3"}}, {FP: "_overflow", Source: "edge", Name: "500 GET /z", Count: 40, Last: now}, }) out := buf.String() for _, want := range []string{"2026-09-07 10:00", "12", "edge", "500 POST /checkout", "abc123", "a.example", "v3", "overflow"} { if !strings.Contains(out, want) { t.Errorf("output missing %q:\n%s", want, out) } } } // TestAvailabilityNamesPlatformEvents: a log-derived row on Availability is // a platform event, and prints as one rather than as the app's own "log". func TestAvailabilityNamesPlatformEvents(t *testing.T) { now := time.Date(2026, 9, 24, 10, 0, 0, 0, time.UTC) in := []apperr.Group{ {FP: "a", Source: apperr.SourceLog, Name: "wake failed: no head", Count: 1, Last: now}, {FP: "b", Source: apperr.SourceEdge, Name: apperr.AvailabilityName(502, apperr.CauseRefused), Count: 4, Last: now}, } var buf bytes.Buffer printErrorGroups(&buf, platformSourced(in)) out := buf.String() for _, want := range []string{"platform wake failed", "edge 502 ยท the instance refused the connection"} { if !strings.Contains(out, want) { t.Errorf("output missing %q:\n%s", want, out) } } if in[0].Source != apperr.SourceLog { t.Fatal("platformSourced must not rewrite its input") } }