Skip to content

Commit

Permalink
chore: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Jul 28, 2022
1 parent dde578f commit d14ee2d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/logx/contextlogger_test.go
Expand Up @@ -29,7 +29,7 @@ func TestTraceLog(t *testing.T) {
otel.SetTracerProvider(tp)
defer otel.SetTracerProvider(otp)

ctx, span := tp.Tracer("foo").Start(context.Background(), "bar")
ctx, span := tp.Tracer("trace-id").Start(context.Background(), "span-id")
defer span.End()

WithContext(ctx).Info(testlog)
Expand All @@ -50,7 +50,7 @@ func TestTraceError(t *testing.T) {
otel.SetTracerProvider(tp)
defer otel.SetTracerProvider(otp)

ctx, span := tp.Tracer("foo1").Start(context.Background(), "bar")
ctx, span := tp.Tracer("trace-id").Start(context.Background(), "span-id")
defer span.End()

var nilCtx context.Context
Expand All @@ -67,10 +67,10 @@ func TestTraceError(t *testing.T) {
l.WithDuration(time.Second).Errorv(testlog)
validate(t, w.String(), true, true)
w.Reset()
l.WithDuration(time.Second).Errorw(testlog, Field("foo1", "bar"))
l.WithDuration(time.Second).Errorw(testlog, Field("basket", "ball"))
validate(t, w.String(), true, true)
assert.True(t, strings.Contains(w.String(), "foo1"), w.String())
assert.True(t, strings.Contains(w.String(), "bar"), w.String())
assert.True(t, strings.Contains(w.String(), "basket"), w.String())
assert.True(t, strings.Contains(w.String(), "ball"), w.String())
}

func TestTraceInfo(t *testing.T) {
Expand All @@ -87,7 +87,7 @@ func TestTraceInfo(t *testing.T) {
otel.SetTracerProvider(tp)
defer otel.SetTracerProvider(otp)

ctx, span := tp.Tracer("foo1").Start(context.Background(), "bar")
ctx, span := tp.Tracer("trace-id").Start(context.Background(), "span-id")
defer span.End()

SetLevel(InfoLevel)
Expand All @@ -101,10 +101,10 @@ func TestTraceInfo(t *testing.T) {
l.WithDuration(time.Second).Infov(testlog)
validate(t, w.String(), true, true)
w.Reset()
l.WithDuration(time.Second).Infow(testlog, Field("foo1", "bar"))
l.WithDuration(time.Second).Infow(testlog, Field("basket", "ball"))
validate(t, w.String(), true, true)
assert.True(t, strings.Contains(w.String(), "foo1"), w.String())
assert.True(t, strings.Contains(w.String(), "bar"), w.String())
assert.True(t, strings.Contains(w.String(), "basket"), w.String())
assert.True(t, strings.Contains(w.String(), "ball"), w.String())
}

func TestTraceInfoConsole(t *testing.T) {
Expand All @@ -124,7 +124,7 @@ func TestTraceInfoConsole(t *testing.T) {
otel.SetTracerProvider(tp)
defer otel.SetTracerProvider(otp)

ctx, span := tp.Tracer("foo").Start(context.Background(), "bar")
ctx, span := tp.Tracer("trace-id").Start(context.Background(), "span-id")
defer span.End()

l := WithContext(ctx)
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestTraceSlow(t *testing.T) {
otel.SetTracerProvider(tp)
defer otel.SetTracerProvider(otp)

ctx, span := tp.Tracer("foo1").Start(context.Background(), "bar")
ctx, span := tp.Tracer("trace-id").Start(context.Background(), "span-id")
defer span.End()

l := WithContext(ctx)
Expand All @@ -168,10 +168,10 @@ func TestTraceSlow(t *testing.T) {
l.WithDuration(time.Second).Slowv(testlog)
validate(t, w.String(), true, true)
w.Reset()
l.WithDuration(time.Second).Sloww(testlog, Field("foo1", "bar"))
l.WithDuration(time.Second).Sloww(testlog, Field("basket", "ball"))
validate(t, w.String(), true, true)
assert.True(t, strings.Contains(w.String(), "foo1"), w.String())
assert.True(t, strings.Contains(w.String(), "bar"), w.String())
assert.True(t, strings.Contains(w.String(), "basket"), w.String())
assert.True(t, strings.Contains(w.String(), "ball"), w.String())
}

func TestTraceWithoutContext(t *testing.T) {
Expand Down

0 comments on commit d14ee2d

Please sign in to comment.