mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-13 14:18:47 +01:00
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package logger_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/netflow/logger"
|
|
"github.com/netbirdio/netbird/client/internal/netflow/types"
|
|
)
|
|
|
|
func TestStore(t *testing.T) {
|
|
logger := logger.New(context.Background())
|
|
logger.Enable()
|
|
|
|
event := types.EventFields{
|
|
FlowID: uuid.New(),
|
|
Type: types.TypeStart,
|
|
Direction: types.Ingress,
|
|
Protocol: 6,
|
|
}
|
|
|
|
wait := func() { time.Sleep(time.Millisecond) }
|
|
wait()
|
|
logger.StoreEvent(event)
|
|
wait()
|
|
|
|
allEvents := logger.GetEvents()
|
|
matched := false
|
|
for _, e := range allEvents {
|
|
if e.EventFields.FlowID == event.FlowID {
|
|
matched = true
|
|
}
|
|
}
|
|
if !matched {
|
|
t.Errorf("didn't match any event")
|
|
}
|
|
|
|
// test disable
|
|
logger.Disable()
|
|
wait()
|
|
logger.StoreEvent(event)
|
|
wait()
|
|
allEvents = logger.GetEvents()
|
|
if len(allEvents) != 0 {
|
|
t.Errorf("expected 0 events, got %d", len(allEvents))
|
|
}
|
|
|
|
// test re-enable
|
|
logger.Enable()
|
|
wait()
|
|
logger.StoreEvent(event)
|
|
wait()
|
|
|
|
allEvents = logger.GetEvents()
|
|
matched = false
|
|
for _, e := range allEvents {
|
|
if e.EventFields.FlowID == event.FlowID {
|
|
matched = true
|
|
}
|
|
}
|
|
if !matched {
|
|
t.Errorf("didn't match any event")
|
|
}
|
|
}
|