forked from boyska/circolog
Added tests for data
This commit is contained in:
parent
c5eee0ea22
commit
02b41aa661
1 changed files with 57 additions and 0 deletions
57
data/data_test.go
Normal file
57
data/data_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gopkg.in/mcuadros/go-syslog.v2/format"
|
||||
)
|
||||
|
||||
var mandatoryKeys = []string{
|
||||
"prog",
|
||||
"client",
|
||||
"host",
|
||||
"msg",
|
||||
"sev",
|
||||
"time",
|
||||
"proc_id",
|
||||
}
|
||||
|
||||
var msgRFC5424 = format.LogParts{
|
||||
"version": 1,
|
||||
"app_name": "test_app",
|
||||
"client": "test_client",
|
||||
"hostname": "my_machine",
|
||||
"proc_id": "spam_process",
|
||||
"message": "test message",
|
||||
"facility": "hell",
|
||||
"timestamp": time.Now(),
|
||||
"severity": 3,
|
||||
}
|
||||
|
||||
var msgRFC3164 = format.LogParts{
|
||||
"tag": "test_tag",
|
||||
"client": "test_client",
|
||||
"hostname": "my_machine",
|
||||
"content": "test message",
|
||||
"severity": 3,
|
||||
"timestamp": time.Now(),
|
||||
"proc_id": "spam_process",
|
||||
}
|
||||
|
||||
var testMessages = []format.LogParts{
|
||||
msgRFC5424,
|
||||
msgRFC3164,
|
||||
}
|
||||
|
||||
func TestLogEntryToMessage(t *testing.T) {
|
||||
for _, msg := range testMessages {
|
||||
parsedMsg := LogEntryToMessage(msg)
|
||||
|
||||
for _, key := range mandatoryKeys {
|
||||
if data, ok := parsedMsg[key]; !ok || data == nil {
|
||||
t.Errorf("Missing key: %s\nmsg: %s\nparsed msg: %s\n", key, msg, parsedMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue