1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/OpenSkywalking-go2sky

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
trace_context_test.go 2.8 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
zhang-wei Отправлено 05.01.2022 08:36 a12c5be
//
// Copyright 2022 SkyAPM org
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package go2sky
import (
"context"
"testing"
)
func TestTraceData(t *testing.T) {
// activeSpan == nil
verifyTraceData(context.Background(), t, "", "", EmptyTraceID, EmptyTraceSegmentID, EmptySpanID)
// activeSpan == NoopSpan
tracer, _ := NewTracer("service")
_, ctx, err := tracer.CreateLocalSpan(context.Background())
if err != nil {
t.Error(err)
}
verifyTraceData(ctx, t, "", "", EmptyTraceID, EmptyTraceSegmentID, EmptySpanID)
// activeSpan == segmentSpan
reporter := &mockRegisterReporter{
success: true,
}
tracer, _ = NewTracer("service", WithInstance("instance"), WithReporter(reporter))
span, ctx, err := tracer.CreateLocalSpan(context.Background())
if err != nil {
t.Error(err)
}
segmentContext := span.(segmentSpan).context()
verifyTraceData(ctx, t, "service", "instance", segmentContext.TraceID, segmentContext.SegmentID, segmentContext.SpanID)
}
func verifyTraceData(ctx context.Context, t *testing.T, serviceName, serviceInstanceName, traceID, traceSegmentID string, spanID int32) {
verifyEqual(t, "ServiceName", serviceName, ServiceName(ctx))
verifyEqual(t, "ServiceInstanceName", serviceInstanceName, ServiceInstanceName(ctx))
verifyEqual(t, "TraceID", traceID, TraceID(ctx))
verifyEqual(t, "TraceSegmentID", traceSegmentID, TraceSegmentID(ctx))
verifyEqual(t, "SpanID", spanID, SpanID(ctx))
}
func verifyEqual(t *testing.T, equalsKey string, expect interface{}, actual interface{}) {
if expect != actual {
t.Errorf("expect%s: %v, actual%s: %v", equalsKey, expect, equalsKey, actual)
}
}
func TestActiveSpan(t *testing.T) {
// activeSpan == nil
verifySpan(context.Background(), t, nil)
// activeSpan == NoopSpan
tracer, _ := NewTracer("service")
noopSpan, ctx, err := tracer.CreateLocalSpan(context.Background())
if err != nil {
t.Error(err)
}
verifySpan(ctx, t, noopSpan)
// activeSpan == segmentSpan
reporter := &mockRegisterReporter{
success: true,
}
tracer, _ = NewTracer("service", WithInstance("instance"), WithReporter(reporter))
span, ctx, err := tracer.CreateLocalSpan(context.Background())
if err != nil {
t.Error(err)
}
verifySpan(ctx, t, span)
}
func verifySpan(ctx context.Context, t *testing.T, expectSpan Span) {
actualSpan := ActiveSpan(ctx)
verifyEqual(t, "ActiveSpan", expectSpan, actualSpan)
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/OpenSkywalking-go2sky.git
git@api.gitlife.ru:oschina-mirror/OpenSkywalking-go2sky.git
oschina-mirror
OpenSkywalking-go2sky
OpenSkywalking-go2sky
master