forked from inthecloud247/heka-clever-plugins
/
firehose_output_test.go
86 lines (68 loc) · 2.18 KB
/
firehose_output_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package heka_clever_plugins
import (
"testing"
"time"
"github.com/mozilla-services/heka/message"
"github.com/mozilla-services/heka/pipeline"
"github.com/mozilla-services/heka/pipelinemock"
"github.com/rafrombrc/gomock/gomock"
"github.com/stretchr/testify/assert"
)
func TestRun(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockOR := pipelinemock.NewMockOutputRunner(mockCtrl)
mockPH := pipelinemock.NewMockPluginHelper(mockCtrl)
mockFirehose := NewMockRecordPutter(mockCtrl)
firehoseOutput := FirehoseOutput{
client: mockFirehose,
}
testChan := make(chan *pipeline.PipelinePack)
mockOR.EXPECT().InChan().Return(testChan)
// Send test input through the channel
input := `{"key":"value"}`
go func() {
testPack := pipeline.PipelinePack{
Message: &message.Message{
Payload: &input,
},
}
testChan <- &testPack
close(testChan)
}()
mockFirehose.EXPECT().PutRecord([]byte(input)).Return(nil)
err := firehoseOutput.Run(mockOR, mockPH)
assert.NoError(t, err, "did not expect err for valid Run()")
}
// TestRunWithTimestamp tests that if a TimestampColumn is provided in the config
// then the Heka message's timestamp gets added to the message with that column name.
func TestRunWithTimestamp(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockOR := pipelinemock.NewMockOutputRunner(mockCtrl)
mockPH := pipelinemock.NewMockPluginHelper(mockCtrl)
mockFirehose := NewMockRecordPutter(mockCtrl)
firehoseOutput := FirehoseOutput{
client: mockFirehose,
timestampColumn: "created",
}
testChan := make(chan *pipeline.PipelinePack)
mockOR.EXPECT().InChan().Return(testChan)
// Send test input through the channel
input := `{}`
timestamp := time.Date(2015, 07, 1, 13, 14, 15, 0, time.UTC).UnixNano()
go func() {
testPack := pipeline.PipelinePack{
Message: &message.Message{
Payload: &input,
Timestamp: ×tamp,
},
}
testChan <- &testPack
close(testChan)
}()
expected := `{"created":"2015-07-01 13:14:15.000"}`
mockFirehose.EXPECT().PutRecord([]byte(expected)).Return(nil)
err := firehoseOutput.Run(mockOR, mockPH)
assert.NoError(t, err, "did not expect err for valid Run()")
}