From 02b41aa661f5e46bf104b6230d4d463c1fa78aa4 Mon Sep 17 00:00:00 2001 From: Blallo Date: Mon, 1 Apr 2019 17:25:30 +0200 Subject: [PATCH] Added tests for data --- data/data_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 data/data_test.go 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) + } + } + } +}