forked from boyska/circolog
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|
|
}
|