1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/debug/log/default_test.go

33 lines
805 B
Go
Raw Normal View History

2019-11-27 18:02:16 +02:00
package log
import (
"reflect"
"testing"
)
func TestLogger(t *testing.T) {
// set size to some value
size := 100
// override the global logger
DefaultLog = NewLog(Size(size))
2019-11-27 18:02:16 +02:00
// make sure we have the right size of the logger ring buffer
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
Info("foobar")
// increase the log level
DefaultLevel = LevelDebug
Debugf("foo %s", "bar")
2019-11-27 18:02:16 +02:00
// Check if the logs are stored in the logger ring buffer
expected := []string{"foobar", "foo bar"}
entries := DefaultLog.Read(Count(len(expected)))
2019-11-27 18:02:16 +02:00
for i, entry := range entries {
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
}
}
}