Skip to content

Commit

Permalink
Cover updating aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Dec 3, 2019
1 parent 1acec08 commit 8c6d690
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cmd/helpers/updatingAggregator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package helpers

import (
"io/ioutil"
"rare/pkg/extractor"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

var testData = `abc 123
def 245
qqq 123
xxx`

type VirtualAggregator struct {
items []string
}

func (s *VirtualAggregator) Sample(element string) {
s.items = append(s.items, element)
}

func (s *VirtualAggregator) ParseErrors() uint64 {
return 0
}

func TestAggregationLoop(t *testing.T) {
// Build a real extractor
input := extractor.ConvertReaderToStringChan("test", ioutil.NopCloser(strings.NewReader(testData)), 1)
ex, err := extractor.New(input, &extractor.Config{
Regex: `(\d+)`,
Extract: "val:{1}",
Workers: 1,
})
assert.NoError(t, err)

// Build a fake aggregator
agg := &VirtualAggregator{}

outputTriggered := 0
RunAggregationLoop(ex, agg, func() {
outputTriggered++
})

// Validation
assert.GreaterOrEqual(t, outputTriggered, 1)
assert.Equal(t, 3, len(agg.items))

// Also validate summary building since we have all the correct context
WriteExtractorSummary(ex)
}

0 comments on commit 8c6d690

Please sign in to comment.