diff --git a/data/data_test.go b/data/data_test.go new file mode 100644 index 0000000..d1dc921 --- /dev/null +++ b/data/data_test.go @@ -0,0 +1,57 @@ +package data + +import ( + "testing" + "time" + + "gopkg.in/mcuadros/go-syslog.v2/format" +) + +var mandatoryKeys = []string{ + "prog", + "client", + "host", + "msg", + "sev", + "time", + "proc_id", +} + +var msgRFC5424 = format.LogParts{ + "version": 1, + "app_name": "test_app", + "client": "test_client", + "hostname": "my_machine", + "proc_id": "spam_process", + "message": "test message", + "facility": "hell", + "timestamp": time.Now(), + "severity": 3, +} + +var msgRFC3164 = format.LogParts{ + "tag": "test_tag", + "client": "test_client", + "hostname": "my_machine", + "content": "test message", + "severity": 3, + "timestamp": time.Now(), + "proc_id": "spam_process", +} + +var testMessages = []format.LogParts{ + msgRFC5424, + msgRFC3164, +} + +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) + } + } + } +}