Пример #1
0
func testMode(
	t *testing.T,
	mode ConnectionMode,
	events [][]common.MapStr,
	expectedSignal bool,
	collectedEvents *[][]common.MapStr,
) {
	defer mode.Close()

	if events != nil {
		ch := make(chan bool, 1)
		signal := outputs.NewChanSignal(ch)
		for _, pubEvents := range events {
			_ = mode.PublishEvents(signal, pubEvents)

			result := <-ch
			assert.Equal(t, expectedSignal, result)
		}

		if collectedEvents != nil {
			assert.Equal(t, len(events), len(*collectedEvents))
			for i := range *collectedEvents {
				expected := events[i]
				actual := (*collectedEvents)[i]
				assert.Equal(t, expected, actual)
			}
		}
	}
}
Пример #2
0
func testMode(
	t *testing.T,
	mode ConnectionMode,
	events []eventInfo,
	expectedSignals []bool,
	collectedEvents *[][]common.MapStr,
) {
	defer mode.Close()

	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 bool, numSignals)
	signal := outputs.NewChanSignal(ch)
	idx := 0
	for _, pubEvents := range events {
		if pubEvents.single {
			for _, event := range pubEvents.events {
				_ = mode.PublishEvent(signal, event)
				if expectedSignals[idx] {
					expectedEvents = append(expectedEvents, []common.MapStr{event})
				}
				idx++
			}
		} else {
			_ = mode.PublishEvents(signal, 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
	}
	assert.Equal(t, expectedSignals, results)

	if collectedEvents != nil {
		assert.Equal(t, len(expectedEvents), len(*collectedEvents))
		for i := range *collectedEvents {
			expected := expectedEvents[i]
			actual := (*collectedEvents)[i]
			assert.Equal(t, expected, actual)
		}
	}
}