github.com/kunnos/engine@v1.13.1/daemon/logger/syslog/syslog_test.go (about) 1 package syslog 2 3 import ( 4 "reflect" 5 "testing" 6 7 syslog "github.com/RackSec/srslog" 8 ) 9 10 func functionMatches(expectedFun interface{}, actualFun interface{}) bool { 11 return reflect.ValueOf(expectedFun).Pointer() == reflect.ValueOf(actualFun).Pointer() 12 } 13 14 func TestParseLogFormat(t *testing.T) { 15 formatter, framer, err := parseLogFormat("rfc5424", "udp") 16 if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) || 17 !functionMatches(syslog.DefaultFramer, framer) { 18 t.Fatal("Failed to parse rfc5424 format", err, formatter, framer) 19 } 20 21 formatter, framer, err = parseLogFormat("rfc5424", "tcp+tls") 22 if err != nil || !functionMatches(rfc5424formatterWithAppNameAsTag, formatter) || 23 !functionMatches(syslog.RFC5425MessageLengthFramer, framer) { 24 t.Fatal("Failed to parse rfc5424 format", err, formatter, framer) 25 } 26 27 formatter, framer, err = parseLogFormat("rfc5424micro", "udp") 28 if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) || 29 !functionMatches(syslog.DefaultFramer, framer) { 30 t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer) 31 } 32 33 formatter, framer, err = parseLogFormat("rfc5424micro", "tcp+tls") 34 if err != nil || !functionMatches(rfc5424microformatterWithAppNameAsTag, formatter) || 35 !functionMatches(syslog.RFC5425MessageLengthFramer, framer) { 36 t.Fatal("Failed to parse rfc5424 (microsecond) format", err, formatter, framer) 37 } 38 39 formatter, framer, err = parseLogFormat("rfc3164", "") 40 if err != nil || !functionMatches(syslog.RFC3164Formatter, formatter) || 41 !functionMatches(syslog.DefaultFramer, framer) { 42 t.Fatal("Failed to parse rfc3164 format", err, formatter, framer) 43 } 44 45 formatter, framer, err = parseLogFormat("", "") 46 if err != nil || !functionMatches(syslog.UnixFormatter, formatter) || 47 !functionMatches(syslog.DefaultFramer, framer) { 48 t.Fatal("Failed to parse empty format", err, formatter, framer) 49 } 50 51 formatter, framer, err = parseLogFormat("invalid", "") 52 if err == nil { 53 t.Fatal("Failed to parse invalid format", err, formatter, framer) 54 } 55 } 56 57 func TestValidateLogOptEmpty(t *testing.T) { 58 emptyConfig := make(map[string]string) 59 if err := ValidateLogOpt(emptyConfig); err != nil { 60 t.Fatal("Failed to parse empty config", err) 61 } 62 }