| 12345678910111213141516171819202122232425262728 |
- package util
- import (
- "context"
- "fmt"
- "testing"
- )
- func TestKVContext(t *testing.T) {
- cxt := context.WithValue(context.Background(), "k1", "v1")
- newCtx := NewKVContext(cxt)
- newCtx.Set("k2", "v2")
- fmt.Println(newCtx.Value("k1"))
- fmt.Println(newCtx.Value("k2"))
- var cctx context.Context = newCtx
- fmt.Println(AssertKVContext(cctx).Get("k2"))
- }
- func BenchmarkName(b *testing.B) {
- for i := 0; i < b.N; i++ {
- newCtx := NewKVContext(context.Background())
- newCtx.Set("k2", "v2")
- newCtx.Value("k2")
- }
- }
|