carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package apperr
2
3import (
4 "testing"
5 "time"
6)
7
8func TestGroupRecords(t *testing.T) {
9 now := time.Date(2026, 9, 7, 10, 0, 0, 0, time.UTC)
10 recs := []Record{
11 {FP: "a", Source: SourceEdge, Kind: KindHTTP, Name: "500 GET /x", Host: "h1", Release: "v1", Count: 3, First: now.Add(-10 * time.Minute), Last: now.Add(-5 * time.Minute), Stack: "s1"},
12 {FP: "a", Source: SourceEdge, Kind: KindHTTP, Name: "500 GET /x", Host: "h2", Release: "v2", Count: 2, First: now.Add(-20 * time.Minute), Last: now.Add(-1 * time.Minute), Stack: "s2"},
13 {FP: "b", Source: SourceLog, Kind: KindLog, Name: "boom", Level: "error", Host: "h1", Count: 1, First: now.Add(-30 * time.Minute), Last: now.Add(-30 * time.Minute)},
14 {FP: OverflowFP, Source: SourceEdge, Name: "500 GET /z", Host: "h1", Count: 40, First: now, Last: now},
15 }
16 gs := GroupRecords(recs)
17 if len(gs) != 3 {
18 t.Fatalf("groups = %d", len(gs))
19 }
20 if gs[0].FP != OverflowFP || gs[1].FP != "a" || gs[2].FP != "b" {
21 t.Fatalf("order by Last desc: %s %s %s", gs[0].FP, gs[1].FP, gs[2].FP)
22 }
23 a := gs[1]
24 if a.Count != 5 || !a.First.Equal(now.Add(-20*time.Minute)) || !a.Last.Equal(now.Add(-1*time.Minute)) {
25 t.Fatalf("a = %+v", a)
26 }
27 if len(a.Hosts) != 2 || a.Hosts[0] != "h1" || a.Hosts[1] != "h2" || len(a.Releases) != 2 {
28 t.Fatalf("a hosts/releases = %v %v", a.Hosts, a.Releases)
29 }
30 if a.Sample.Stack != "s2" {
31 t.Fatal("sample must be the earliest record")
32 }
33}
34