/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
net/gtrace/gtrace_z_unit_test.go
55 строк
1 KB
John Guo
add WithUUID for package gtrace (#2176)
08 окт 2022, 16:44
Не верифицирован
08 окт 2022, 16:44
dba903c
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gtrace_test import ( "context" "testing" "github.com/gogf/gf/v2/net/gtrace" "github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/text/gstr" ) func TestWithTraceID(t *testing.T) { var ( ctx = context.Background() uuid = `a323f910-f690-11ec-963d-79c0b7fcf119` ) gtest.C(t, func(t *gtest.T) { newCtx, err := gtrace.WithTraceID(ctx, uuid) t.AssertNE(err, nil) t.Assert(newCtx, ctx) }) gtest.C(t, func(t *gtest.T) { var traceId = gstr.Replace(uuid, "-", "") newCtx, err := gtrace.WithTraceID(ctx, traceId) t.AssertNil(err) t.AssertNE(newCtx, ctx) t.Assert(gtrace.GetTraceID(ctx), "") t.Assert(gtrace.GetTraceID(newCtx), traceId) }) } func TestWithUUID(t *testing.T) { var ( ctx = context.Background() uuid = `a323f910-f690-11ec-963d-79c0b7fcf119` ) gtest.C(t, func(t *gtest.T) { newCtx, err := gtrace.WithTraceID(ctx, uuid) t.AssertNE(err, nil) t.Assert(newCtx, ctx) }) gtest.C(t, func(t *gtest.T) { newCtx, err := gtrace.WithUUID(ctx, uuid) t.AssertNil(err) t.AssertNE(newCtx, ctx) t.Assert(gtrace.GetTraceID(ctx), "") t.Assert(gtrace.GetTraceID(newCtx), gstr.Replace(uuid, "-", "")) }) }