test: fix fails (#1970)

master
Kevin Wan 3 years ago committed by GitHub
parent af05219b70
commit c44edd7cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ package logx
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io"
"strings" "strings"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -193,6 +194,22 @@ func TestTraceWithoutContext(t *testing.T) {
func validate(t *testing.T, body string, expectedTrace, expectedSpan bool) { func validate(t *testing.T, body string, expectedTrace, expectedSpan bool) {
var val mockValue 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.Nil(t, json.Unmarshal([]byte(body), &val), body)
assert.Equal(t, expectedTrace, len(val.Trace) > 0, body) assert.Equal(t, expectedTrace, len(val.Trace) > 0, body)
assert.Equal(t, expectedSpan, len(val.Span) > 0, body) assert.Equal(t, expectedSpan, len(val.Span) > 0, body)

Loading…
Cancel
Save