This commit is contained in:
2026-04-03 11:19:00 +02:00
parent 2416f528bb
commit 26265e776c
14 changed files with 533 additions and 11 deletions
+52
View File
@@ -0,0 +1,52 @@
package collector
import (
"context"
"testing"
"time"
"git.tornberg.me/go-otel/internal/websocket"
)
type mockStore struct {
entries []websocket.HistoryEntry
}
func (m *mockStore) Append(ctx context.Context, entry websocket.HistoryEntry) error {
m.entries = append(m.entries, entry)
return nil
}
func (m *mockStore) GetHistory(ctx context.Context, limit int) ([]websocket.HistoryEntry, error) {
return m.entries, nil
}
func (m *mockStore) Search(ctx context.Context, query string, limit int) ([]websocket.HistoryEntry, error) {
return m.entries, nil
}
func TestCollectorWithStore(t *testing.T) {
store := &mockStore{}
coll := New(nil, 10, store)
coll.addToHistory(websocket.DataTypeLogs, map[string]interface{}{"msg": "test"})
// Give it a moment since it's asynchronous
timeout := time.After(100 * time.Millisecond)
for {
select {
case <-timeout:
t.Fatal("timed out waiting for entry to be appended to store")
default:
if len(store.entries) > 0 {
goto OK
}
time.Sleep(10 * time.Millisecond)
}
}
OK:
if store.entries[0].Type != "logs" {
t.Errorf("expected type 'logs', got %s", store.entries[0].Type)
}
}