package collector import ( "os" "testing" "time" "codeberg.org/pata1704/guenther/internal/config" "codeberg.org/pata1704/guenther/pkg/types" "github.com/stretchr/testify/assert" ) func TestLogCollector_ProcessLine(t *testing.T) { // 1. Create temporary log file tmpFile, err := os.CreateTemp("", "test_log_*.log") assert.NoError(t, err) defer os.Remove(tmpFile.Name()) outputChan := make(chan types.LogEvent, 10) healthChan := make(chan types.StageHealth, 10) cfg := &config.Config{} cfg.Ingestion.LogPath = tmpFile.Name() cfg.Drain.Depth = 4 cfg.Drain.SimThreshold = 0.5 cfg.Drain.MaxChildren = 100 collector := NewLogCollector(cfg, outputChan, healthChan) // 2. Test line processing with specific regex patterns testLine := "2026-02-26 13:00:00.123456 INFO Transfer from 192.168.1.1:8080 completed (duration=1.23)" collector.processLine(testLine) select { case ev := <-outputChan: assert.Equal(t, "INFO", ev.Severity) assert.Greater(t, ev.TemplateID, 0) t.Logf("Extracted parameters: %v", ev.Params) // Unconfigured Drain3 template yields empty map assert.GreaterOrEqual(t, len(ev.Params), 0) case <-time.After(1 * time.Second): t.Fatal("Timeout waiting for LogEvent") } }