zlog/ctx_test.go

29 lines
580 B
Go
Raw Normal View History

2017-05-19 19:59:10 +00:00
package zerolog
import (
"context"
"io/ioutil"
"reflect"
"testing"
)
func TestCtx(t *testing.T) {
log := New(ioutil.Discard)
ctx := log.WithContext(context.Background())
log2, ok := FromContext(ctx)
if !ok {
t.Error("Expected ok=true from FromContext")
}
if !reflect.DeepEqual(log, log2) {
t.Error("FromContext did not return the expected logger")
}
log2, ok = FromContext(context.Background())
if ok {
t.Error("Expected ok=false from FromContext")
}
if !reflect.DeepEqual(log2, Logger{}) {
t.Error("FromContext did not return the expected logger")
}
}