2019-11-27 18:02:16 +02:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLogger(t *testing.T) {
|
2019-11-27 19:31:35 +02:00
|
|
|
// set size to some value
|
|
|
|
size := 100
|
|
|
|
// override the global logger
|
2019-11-28 20:08:48 +02:00
|
|
|
DefaultLog = NewLog(Size(size))
|
2019-11-27 18:02:16 +02:00
|
|
|
// make sure we have the right size of the logger ring buffer
|
2019-11-28 20:08:48 +02:00
|
|
|
if DefaultLog.(*defaultLog).Size() != size {
|
|
|
|
t.Errorf("expected buffer size: %d, got: %d", size, DefaultLog.(*defaultLog).Size())
|
2019-11-27 18:02:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Log some cruft
|
2019-11-27 19:31:35 +02:00
|
|
|
Info("foobar")
|
|
|
|
// increase the log level
|
2019-11-28 20:08:48 +02:00
|
|
|
DefaultLevel = LevelDebug
|
2019-11-27 19:31:35 +02:00
|
|
|
Debugf("foo %s", "bar")
|
2019-11-27 18:02:16 +02:00
|
|
|
|
|
|
|
// Check if the logs are stored in the logger ring buffer
|
2019-11-27 19:31:35 +02:00
|
|
|
expected := []string{"foobar", "foo bar"}
|
2019-11-28 20:08:48 +02:00
|
|
|
entries := DefaultLog.Read(Count(len(expected)))
|
2019-11-27 18:02:16 +02:00
|
|
|
for i, entry := range entries {
|
2019-11-27 19:31:35 +02:00
|
|
|
if !reflect.DeepEqual(entry.Value, expected[i]) {
|
|
|
|
t.Errorf("expected %s, got %s", expected[i], entry.Value)
|
2019-11-27 18:02:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|