2018-02-05 16:05:59 -05:00
|
|
|
package syslog // import "github.com/docker/docker/daemon/logger/syslog"
|
2016-02-03 15:59:27 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2016-08-15 16:25:05 -04:00
|
|
|
|
|
|
|
syslog "github.com/RackSec/srslog"
|
2016-02-03 15:59:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func functionMatches(expectedFun interface{}, actualFun interface{}) bool {
|
|
|
|
return reflect.ValueOf(expectedFun).Pointer() == reflect.ValueOf(actualFun).Pointer()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseLogFormat(t *testing.T) {
|
2016-06-29 11:44:00 -04:00
|
|
|
formatter, framer, err := parseLogFormat("rfc5424", "udp")
|
|
|
|
if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) ||
|
|
|
|
!functionMatches(syslog.DefaultFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse rfc5424 format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
|
|
|
formatter, framer, err = parseLogFormat("rfc5424", "tcp+tls")
|
2016-02-03 15:59:27 -05:00
|
|
|
if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) ||
|
|
|
|
!functionMatches(syslog.RFC5425MessageLengthFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse rfc5424 format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:44:00 -04:00
|
|
|
formatter, framer, err = parseLogFormat("rfc5424micro", "udp")
|
|
|
|
if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) ||
|
|
|
|
!functionMatches(syslog.DefaultFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
|
|
|
formatter, framer, err = parseLogFormat("rfc5424micro", "tcp+tls")
|
2016-04-07 02:03:28 -04:00
|
|
|
if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) ||
|
|
|
|
!functionMatches(syslog.RFC5425MessageLengthFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:44:00 -04:00
|
|
|
formatter, framer, err = parseLogFormat("rfc3164", "")
|
2016-02-03 15:59:27 -05:00
|
|
|
if err != nil || !functionMatches(syslog.RFC3164Formatter, formatter) ||
|
|
|
|
!functionMatches(syslog.DefaultFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse rfc3164 format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:44:00 -04:00
|
|
|
formatter, framer, err = parseLogFormat("", "")
|
2016-02-03 15:59:27 -05:00
|
|
|
if err != nil || !functionMatches(syslog.UnixFormatter, formatter) ||
|
|
|
|
!functionMatches(syslog.DefaultFramer, framer) {
|
|
|
|
t.Fatal("Failed to parse empty format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:44:00 -04:00
|
|
|
formatter, framer, err = parseLogFormat("invalid", "")
|
2016-02-03 15:59:27 -05:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Failed to parse invalid format", err, formatter, framer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateLogOptEmpty(t *testing.T) {
|
|
|
|
emptyConfig := make(map[string]string)
|
|
|
|
if err := ValidateLogOpt(emptyConfig); err != nil {
|
|
|
|
t.Fatal("Failed to parse empty config", err)
|
|
|
|
}
|
|
|
|
}
|