2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-15 19:46:12 +00:00
|
|
|
gsyslog "github.com/hashicorp/go-syslog"
|
2015-08-16 20:54:49 +00:00
|
|
|
"github.com/hashicorp/logutils"
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2015-08-16 20:54:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyslogFilter(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2015-08-16 20:54:49 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
t.Skip("Syslog not supported on Windows")
|
|
|
|
}
|
|
|
|
if os.Getenv("TRAVIS") == "true" {
|
|
|
|
t.Skip("Syslog not supported on travis-ci")
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|