Compare commits

...

2 commits

Author SHA1 Message Date
2e1ab137ea
Better tests for data 2019-04-01 20:47:42 +02:00
02b41aa661
Added tests for data 2019-04-01 17:25:30 +02:00

58
data/data_test.go Normal file
View file

@ -0,0 +1,58 @@
package data
import (
"testing"
"time"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
var timeNow = time.Now()
var returnValues = map[string]interface{}{
"prog": "test_app",
"client": "test_client",
"host": "my_machine",
"msg": "test message",
"sev": 3,
"time": timeNow,
}
var msgRFC5424 = format.LogParts{
"version": 1,
"app_name": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"proc_id": "spam_process",
"message": returnValues["msg"],
"facility": "hell",
"timestamp": returnValues["time"],
"severity": returnValues["sev"],
}
var msgRFC3164 = format.LogParts{
"tag": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"content": returnValues["msg"],
"severity": returnValues["sev"],
"timestamp": returnValues["time"],
"proc_id": "spam_process",
}
var testMessages = []format.LogParts{
msgRFC5424,
msgRFC3164,
}
func TestLogEntryToMessage(t *testing.T) {
for _, msg := range testMessages {
parsedMsg := LogEntryToMessage(msg)
for key, value := range returnValues {
if data, ok := parsedMsg[key]; !ok || data != value {
t.Errorf("Missing/wrong key: %s\nmsg: %s\nparsed msg: %s\n", key, value, data)
}
}
}
}