Move logger
This commit is contained in:
32
debug/log/memory/memory_test.go
Normal file
32
debug/log/memory/memory_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/micro/go-micro/debug/log"
|
||||
)
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
// set size to some value
|
||||
size := 100
|
||||
// override the global logger
|
||||
lg := NewLog(log.Size(size))
|
||||
// make sure we have the right size of the logger ring buffer
|
||||
if lg.(*memoryLog).Size() != size {
|
||||
t.Errorf("expected buffer size: %d, got: %d", size, lg.(*memoryLog).Size())
|
||||
}
|
||||
|
||||
// Log some cruft
|
||||
lg.Write(log.Record{Value: "foobar"})
|
||||
lg.Write(log.Record{Value: "foo bar"})
|
||||
|
||||
// Check if the logs are stored in the logger ring buffer
|
||||
expected := []string{"foobar", "foo bar"}
|
||||
entries, _ := lg.Read(log.Count(len(expected)))
|
||||
for i, entry := range entries {
|
||||
if !reflect.DeepEqual(entry.Value, expected[i]) {
|
||||
t.Errorf("expected %s, got %s", expected[i], entry.Value)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user