forked from lileio/logr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logr_test.go
57 lines (47 loc) · 1.41 KB
/
logr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package logr_test
import (
"context"
"testing"
"github.com/gmaliar/logr"
"github.com/gmaliar/logr/logrfakes"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestLogr(t *testing.T) {
l := logr.WithCtx(context.Background())
assert.NotNil(t, l)
}
func TestLogrWithDifferentLogger(t *testing.T) {
l := logr.NewWithLogger(logrus.StandardLogger()).WithContext(context.Background())
assert.NotNil(t, l)
}
func TestLogrWithZipkinContext(t *testing.T) {
tracer := mocktracer.New()
opentracing.SetGlobalTracer(tracer)
span := tracer.StartSpan("test_logger")
ctx := opentracing.ContextWithSpan(context.Background(), span)
fl := &logrfakes.FakeFieldLogger{}
fl.WithFieldsReturns(logrus.WithFields(logrus.Fields{
"animal": "walrus",
}))
l := logr.WithCtx(ctx)
l.Logger = fl
l.Infof(":aasdasd")
assert.NotNil(t, l)
}
func TestLogrWithDifferentLoggerZipkinContext(t *testing.T) {
tracer := mocktracer.New()
opentracing.SetGlobalTracer(tracer)
span := tracer.StartSpan("test_logger")
ctx := opentracing.ContextWithSpan(context.Background(), span)
fl := &logrfakes.FakeFieldLogger{}
fl.WithFieldsReturns(logrus.WithFields(logrus.Fields{
"animal": "walrus",
}))
l := logr.NewWithLogger(logrus.StandardLogger()).WithContext(ctx)
l.Logger = fl
l.Infof(":aasdasd")
assert.NotNil(t, l)
}