forked from tsaikd/gogstash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinputexec_unix_test.go
70 lines (58 loc) · 1.25 KB
/
inputexec_unix_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
package inputexec
import (
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/tsaikd/gogstash/config"
)
var (
logger = config.Logger
)
func init() {
logger.Level = logrus.DebugLevel
config.RegistInputHandler(ModuleName, InitHandler)
}
func Test_text(t *testing.T) {
require := require.New(t)
require.NotNil(require)
conf, err := config.LoadFromString(`{
"input": [{
"type": "exec",
"command": "uptime",
"args": [],
"interval": 1,
"message_prefix": "%{@timestamp} "
},{
"type": "exec",
"command": "whoami",
"args": [],
"interval": 3,
"message_prefix": "%{@timestamp} "
}]
}`)
require.NoError(err)
err = conf.RunInputs()
require.NoError(err)
waitsec := 7
logger.Infof("Wait for %d seconds", waitsec)
time.Sleep(time.Duration(waitsec) * time.Second)
}
func Test_json(t *testing.T) {
require := require.New(t)
require.NotNil(require)
conf, err := config.LoadFromString(`{
"input": [{
"type": "exec",
"command": "./test_json.sh",
"interval": 1,
"message_type": "json"
}]
}`)
require.NoError(err)
err = conf.RunInputs()
require.NoError(err)
waitsec := 3
logger.Infof("Wait for %d seconds", waitsec)
time.Sleep(time.Duration(waitsec) * time.Second)
}