forked from thecubed/gogstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputemail_test.go
58 lines (50 loc) · 1.21 KB
/
outputemail_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
package outputemail
import (
"context"
"strings"
"testing"
"time"
"github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
"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_output_email_module(t *testing.T) {
assert := assert.New(t)
assert.NotNil(assert)
require := require.New(t)
require.NotNil(require)
// Please fill the correct email info xxx is just a placeholder
ctx := context.Background()
conf, err := config.LoadFromYAML([]byte(strings.TrimSpace(`
debugch: true
output:
- type: email
address: "xxx"
from: "xxx"
to: "xxx"
cc: "xxx"
use_tls: false
port: 25
username: "xxx"
password: "xxx"
subject: "outputemail test subject"
`)))
require.NoError(err)
require.NoError(conf.Start(ctx))
conf.TestInputEvent(logevent.LogEvent{
Timestamp: time.Now(),
Message: "outputemail test message",
})
if event, err := conf.TestGetOutputEvent(300 * time.Millisecond); assert.NoError(err) {
require.Equal("outputemail test message", event.Message)
}
}