|
|
@ -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)
|
|
|
|