better handling
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user