1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-10 00:29:01 +02:00
kratos/pkg/net/trace/context_test.go
2019-02-01 15:57:43 +08:00

27 lines
575 B
Go

package trace
import (
"testing"
)
func TestSpanContext(t *testing.T) {
pctx := &spanContext{
parentID: genID(),
spanID: genID(),
traceID: genID(),
flags: flagSampled,
}
if !pctx.isSampled() {
t.Error("expect sampled")
}
value := pctx.String()
t.Logf("bili-trace-id: %s", value)
pctx2, err := contextFromString(value)
if err != nil {
t.Error(err)
}
if pctx2.parentID != pctx.parentID || pctx2.spanID != pctx.spanID || pctx2.traceID != pctx.traceID || pctx2.flags != pctx.flags {
t.Errorf("wrong spancontext get %+v -> %+v", pctx, pctx2)
}
}