func TestMode( t *testing.T, mode mode.ConnectionMode, opts outputs.Options, data []EventInfo, expectedSignals []bool, collected *[][]outputs.Data, ) { defer func() { err := mode.Close() if err != nil { t.Fatal(err) } }() if data == nil { return } results, expectedData := PublishWith(t, mode, opts, data, expectedSignals) assert.Equal(t, expectedSignals, results) if collected != nil { assert.Equal(t, len(expectedData), len(*collected)) if len(expectedData) == len(*collected) { for i := range *collected { expected := expectedData[i] actual := (*collected)[i] assert.Equal(t, expected, actual) } } } }
func TestMode( t *testing.T, mode mode.ConnectionMode, opts outputs.Options, events []EventInfo, expectedSignals []bool, collectedEvents *[][]common.MapStr, ) { defer func() { err := mode.Close() if err != nil { t.Fatal(err) } }() if events == nil { return } numSignals := 0 for _, pubEvents := range events { if pubEvents.Single { numSignals += len(pubEvents.Events) } else { numSignals++ } } var expectedEvents [][]common.MapStr ch := make(chan op.SignalResponse, numSignals) signal := &op.SignalChannel{ch} idx := 0 for _, pubEvents := range events { if pubEvents.Single { for _, event := range pubEvents.Events { _ = mode.PublishEvent(signal, opts, event) if expectedSignals[idx] { expectedEvents = append(expectedEvents, []common.MapStr{event}) } idx++ } } else { _ = mode.PublishEvents(signal, opts, pubEvents.Events) if expectedSignals[idx] { expectedEvents = append(expectedEvents, pubEvents.Events) } idx++ } } results := make([]bool, len(expectedSignals)) for i := 0; i < len(expectedSignals); i++ { results[i] = <-ch == op.SignalCompleted } assert.Equal(t, expectedSignals, results) if collectedEvents != nil { assert.Equal(t, len(expectedEvents), len(*collectedEvents)) if len(expectedEvents) == len(*collectedEvents) { for i := range *collectedEvents { expected := expectedEvents[i] actual := (*collectedEvents)[i] assert.Equal(t, expected, actual) } } } }