test: fix fails (#1970)

This commit is contained in:
Kevin Wan
2022-06-05 11:51:21 +08:00
committed by GitHub
parent af05219b70
commit c44edd7cac

View File

@@ -3,6 +3,7 @@ package logx
import (
"context"
"encoding/json"
"io"
"strings"
"sync/atomic"
"testing"
@@ -193,6 +194,22 @@ func TestTraceWithoutContext(t *testing.T) {
func validate(t *testing.T, body string, expectedTrace, expectedSpan bool) {
var val mockValue
dec := json.NewDecoder(strings.NewReader(body))
for {
var doc mockValue
err := dec.Decode(&doc)
if err == io.EOF {
// all done
break
}
if err != nil {
continue
}
val = doc
}
assert.Nil(t, json.Unmarshal([]byte(body), &val), body)
assert.Equal(t, expectedTrace, len(val.Trace) > 0, body)
assert.Equal(t, expectedSpan, len(val.Span) > 0, body)