forked from tsaikd/gogstash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
outputredis_test.go
71 lines (58 loc) · 1.32 KB
/
outputredis_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
package outputredis
import (
"math/rand"
"reflect"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/tsaikd/gogstash/config"
"github.com/tsaikd/gogstash/config/logevent"
)
var (
logger = config.Logger
)
func init() {
logger.Level = logrus.DebugLevel
config.RegistOutputHandler(ModuleName, InitHandler)
}
func Test_main(t *testing.T) {
require := require.New(t)
require.NotNil(require)
conf, err := config.LoadFromString(`{
"output": [{
"type": "redis",
"host": ["127.0.0.1:6379"]
}]
}`)
require.NoError(err)
err = conf.RunOutputs()
require.NoError(err)
evchan := conf.Get(reflect.TypeOf(make(chan logevent.LogEvent))).
Interface().(chan logevent.LogEvent)
evchan <- logevent.LogEvent{
Timestamp: time.Now(),
Message: "outputstdout test message",
}
// test random time event only
//testRandomTimeEvent(t, evchan)
}
func testRandomTimeEvent(t *testing.T, evchan chan logevent.LogEvent) {
ch := make(chan int, 5)
rand.Seed(time.Now().UnixNano())
for j := 0; j < 5; j++ {
go func() {
for i := 1; i < 120; i++ {
evchan <- logevent.LogEvent{
Timestamp: time.Now(),
Message: "outputredis test message",
}
time.Sleep(time.Duration(rand.Intn(2000)) * time.Millisecond)
}
ch <- j
}()
}
for j := 0; j < 5; j++ {
<-ch
}
}