-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |