1
0
Fork 0
forked from boyska/circolog

Added tests for data

This commit is contained in:
Blallo 2019-04-01 17:25:30 +02:00
parent c5eee0ea22
commit 02b41aa661
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

57
data/data_test.go Normal file
View 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)
}
}
}
}