mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 11:18:02 +08:00
42 lines
978 B
Go
42 lines
978 B
Go
// 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 gctx_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func Test_New(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
ctx := gctx.New()
|
|
t.AssertNE(ctx, nil)
|
|
t.AssertNE(gctx.CtxId(ctx), "")
|
|
})
|
|
}
|
|
|
|
func Test_WithCtx(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
ctx := context.WithValue(context.TODO(), "TEST", 1)
|
|
ctx = gctx.WithCtx(ctx)
|
|
t.AssertNE(gctx.CtxId(ctx), "")
|
|
t.Assert(ctx.Value("TEST"), 1)
|
|
})
|
|
}
|
|
|
|
func Test_SetInitCtx(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
ctx := context.WithValue(context.TODO(), "TEST", 1)
|
|
gctx.SetInitCtx(ctx)
|
|
t.AssertNE(gctx.GetInitCtx(), "")
|
|
t.Assert(gctx.GetInitCtx().Value("TEST"), 1)
|
|
})
|
|
}
|