forked from tsaikd/gogstash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
outputelastic_test.go
55 lines (46 loc) · 1.1 KB
/
outputelastic_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
package outputelastic
import (
"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": "elastic",
"url": "http://127.0.0.1:9200",
"index": "testindex",
"document_type": "testtype",
"document_id": "%{fieldstring}"
}]
}`)
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",
Extra: map[string]interface{}{
"fieldstring": "ABC",
"fieldnumber": 123,
},
}
waitsec := 1
logger.Infof("Wait for %d seconds", waitsec)
time.Sleep(time.Duration(waitsec) * time.Second)
}