1
0
Fork 0
rozštěpen z boyska/circolog
circolog/data/data_test.go
2019-04-01 17:25:30 +02:00

57 řádky
1 KiB
Go

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)
}
}
}
}