better handling

This commit is contained in:
2026-04-05 09:47:25 +02:00
parent 0fd17e4944
commit 988ea1d919
5 changed files with 357 additions and 282 deletions
+30
View File
@@ -50,3 +50,33 @@ OK:
t.Errorf("expected type 'logs', got %s", store.entries[0].Type)
}
}
func TestCollectorHistoryLimit(t *testing.T) {
coll := New(nil, 10, nil)
for i := 0; i < 10; i++ {
coll.addToHistory(websocket.DataTypeLogs, map[string]interface{}{"msg": i})
}
history := coll.GetHistory(10)
if len(history) != 10 {
t.Errorf("expected 10 entries, got %d", len(history))
}
history = coll.GetHistory(5)
if len(history) != 5 {
t.Errorf("expected 5 entries, got %d", len(history))
}
// Should default to historySize (10)
history = coll.GetHistory(0)
if len(history) != 10 {
t.Errorf("expected default limit to be historySize (10), got %d", len(history))
}
// Should not crash on large limit, just return what it has
history = coll.GetHistory(100)
if len(history) != 10 {
t.Errorf("expected 10 entries even with limit 100, got %d", len(history))
}
}