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