diff --git a/data/data_test.go b/data/data_test.go index d1dc921..196caab 100644 --- a/data/data_test.go +++ b/data/data_test.go @@ -7,35 +7,36 @@ import ( "gopkg.in/mcuadros/go-syslog.v2/format" ) -var mandatoryKeys = []string{ - "prog", - "client", - "host", - "msg", - "sev", - "time", - "proc_id", +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": "test_app", - "client": "test_client", - "hostname": "my_machine", + "app_name": returnValues["prog"], + "client": returnValues["client"], + "hostname": returnValues["host"], "proc_id": "spam_process", - "message": "test message", + "message": returnValues["msg"], "facility": "hell", - "timestamp": time.Now(), - "severity": 3, + "timestamp": returnValues["time"], + "severity": returnValues["sev"], } var msgRFC3164 = format.LogParts{ - "tag": "test_tag", - "client": "test_client", - "hostname": "my_machine", - "content": "test message", - "severity": 3, - "timestamp": time.Now(), + "tag": returnValues["prog"], + "client": returnValues["client"], + "hostname": returnValues["host"], + "content": returnValues["msg"], + "severity": returnValues["sev"], + "timestamp": returnValues["time"], "proc_id": "spam_process", } @@ -48,9 +49,9 @@ 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) + 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) } } }