2014-10-14 05:38:12 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
2015-07-28 16:34:24 +00:00
|
|
|
"os"
|
2014-10-17 18:24:10 +00:00
|
|
|
"runtime"
|
2014-10-14 05:38:12 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-syslog"
|
|
|
|
"github.com/hashicorp/logutils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyslogFilter(t *testing.T) {
|
2014-10-17 18:24:10 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
2015-07-28 16:34:24 +00:00
|
|
|
t.Skip("Syslog not supported on Windows")
|
2014-10-17 18:24:10 +00:00
|
|
|
}
|
2015-07-28 16:34:24 +00:00
|
|
|
if os.Getenv("TRAVIS") == "true" {
|
|
|
|
t.Skip("Syslog not supported on travis-ci")
|
|
|
|
}
|
|
|
|
|
2014-10-14 05:38:12 +00:00
|
|
|
l, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, "LOCAL0", "consul")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
filt := LevelFilter()
|
|
|
|
filt.MinLevel = logutils.LogLevel("INFO")
|
|
|
|
|
|
|
|
s := &SyslogWrapper{l, filt}
|
|
|
|
n, err := s.Write([]byte("[INFO] test"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if n == 0 {
|
|
|
|
t.Fatalf("should have logged")
|
|
|
|
}
|
|
|
|
|
|
|
|
n, err = s.Write([]byte("[DEBUG] test"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if n != 0 {
|
|
|
|
t.Fatalf("should not have logged")
|
|
|
|
}
|
|
|
|
}
|