carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/apperr"
10)
11
12func TestPrintErrorGroups(t *testing.T) {
13 now := time.Date(2026, 9, 7, 10, 0, 0, 0, time.UTC)
14 var buf bytes.Buffer
15 printErrorGroups(&buf, []apperr.Group{
16 {FP: "abc123", Source: "edge", Name: "500 POST /checkout", Count: 12, Last: now, Hosts: []string{"a.example"}, Releases: []string{"v3"}},
17 {FP: "_overflow", Source: "edge", Name: "500 GET /z", Count: 40, Last: now},
18 })
19 out := buf.String()
20 for _, want := range []string{"2026-09-07 10:00", "12", "edge", "500 POST /checkout", "abc123", "a.example", "v3", "overflow"} {
21 if !strings.Contains(out, want) {
22 t.Errorf("output missing %q:\n%s", want, out)
23 }
24 }
25}
26
27// TestAvailabilityNamesPlatformEvents: a log-derived row on Availability is
28// a platform event, and prints as one rather than as the app's own "log".
29func TestAvailabilityNamesPlatformEvents(t *testing.T) {
30 now := time.Date(2026, 9, 24, 10, 0, 0, 0, time.UTC)
31 in := []apperr.Group{
32 {FP: "a", Source: apperr.SourceLog, Name: "wake failed: no head", Count: 1, Last: now},
33 {FP: "b", Source: apperr.SourceEdge, Name: apperr.AvailabilityName(502, apperr.CauseRefused), Count: 4, Last: now},
34 }
35 var buf bytes.Buffer
36 printErrorGroups(&buf, platformSourced(in))
37 out := buf.String()
38 for _, want := range []string{"platform wake failed", "edge 502 · the instance refused the connection"} {
39 if !strings.Contains(out, want) {
40 t.Errorf("output missing %q:\n%s", want, out)
41 }
42 }
43 if in[0].Source != apperr.SourceLog {
44 t.Fatal("platformSourced must not rewrite its input")
45 }
46}
47