1
0
Fork 0
forked from boyska/circolog

Better tests for data

This commit is contained in:
Blallo 2019-04-01 20:47:42 +02:00
parent 02b41aa661
commit 2e1ab137ea
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

View file

@ -7,35 +7,36 @@ import (
"gopkg.in/mcuadros/go-syslog.v2/format"
)
var mandatoryKeys = []string{
"prog",
"client",
"host",
"msg",
"sev",
"time",
"proc_id",
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": "test_app",
"client": "test_client",
"hostname": "my_machine",
"app_name": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"proc_id": "spam_process",
"message": "test message",
"message": returnValues["msg"],
"facility": "hell",
"timestamp": time.Now(),
"severity": 3,
"timestamp": returnValues["time"],
"severity": returnValues["sev"],
}
var msgRFC3164 = format.LogParts{
"tag": "test_tag",
"client": "test_client",
"hostname": "my_machine",
"content": "test message",
"severity": 3,
"timestamp": time.Now(),
"tag": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"content": returnValues["msg"],
"severity": returnValues["sev"],
"timestamp": returnValues["time"],
"proc_id": "spam_process",
}
@ -48,9 +49,9 @@ 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)
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)
}
}
}