MCPcopy
hub / github.com/crowdsecurity/crowdsec / assertEvents

Function assertEvents

pkg/acquisition/modules/http/http_test.go:409–445  ·  view source on GitHub ↗
(out chan pipeline.Event, expected []string, errChan chan error)

Source from the content-addressed store, hash-verified

407}
408
409func assertEvents(out chan pipeline.Event, expected []string, errChan chan error) {
410 readLines := []pipeline.Event{}
411
412 for range expected {
413 select {
414 case event := <-out:
415 readLines = append(readLines, event)
416 case <-time.After(2 * time.Second):
417 errChan <- errors.New("timeout waiting for event")
418 return
419 }
420 }
421
422 if len(readLines) != len(expected) {
423 errChan <- fmt.Errorf("expected %d lines, got %d", len(expected), len(readLines))
424 return
425 }
426
427 for i, evt := range readLines {
428 if evt.Line.Raw != expected[i] {
429 errChan <- fmt.Errorf(`expected %s, got '%+v'`, expected, evt.Line.Raw)
430 return
431 }
432
433 if evt.Line.Src != "127.0.0.1" {
434 errChan <- fmt.Errorf("expected '127.0.0.1', got '%s'", evt.Line.Src)
435 return
436 }
437
438 if evt.Line.Module != "http" {
439 errChan <- fmt.Errorf("expected 'http', got '%s'", evt.Line.Module)
440 return
441 }
442 }
443
444 errChan <- nil
445}
446
447func TestStreamingAcquisitionTimeout(t *testing.T) {
448 ctx := t.Context()

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…