1
0
Fork 0
forked from boyska/circolog
circolog/data/data_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

2019-04-01 17:25:30 +02:00
package data
import (
"testing"
"time"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
2019-04-01 20:47:42 +02:00
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,
2019-04-01 17:25:30 +02:00
}
var msgRFC5424 = format.LogParts{
"version": 1,
2019-04-01 20:47:42 +02:00
"app_name": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
2019-04-01 17:25:30 +02:00
"proc_id": "spam_process",
2019-04-01 20:47:42 +02:00
"message": returnValues["msg"],
2019-04-01 17:25:30 +02:00
"facility": "hell",
2019-04-01 20:47:42 +02:00
"timestamp": returnValues["time"],
"severity": returnValues["sev"],
2019-04-01 17:25:30 +02:00
}
var msgRFC3164 = format.LogParts{
2019-04-01 20:47:42 +02:00
"tag": returnValues["prog"],
"client": returnValues["client"],
"hostname": returnValues["host"],
"content": returnValues["msg"],
"severity": returnValues["sev"],
"timestamp": returnValues["time"],
2019-04-01 17:25:30 +02:00
"proc_id": "spam_process",
}
var testMessages = []format.LogParts{
msgRFC5424,
msgRFC3164,
}
func TestLogEntryToMessage(t *testing.T) {
for _, msg := range testMessages {
parsedMsg := LogEntryToMessage(msg)
2019-04-01 20:47:42 +02:00
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)
2019-04-01 17:25:30 +02:00
}
}
}
}