kv_context_test.go 517 B

12345678910111213141516171819202122232425262728
  1. package util
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. )
  7. func TestKVContext(t *testing.T) {
  8. cxt := context.WithValue(context.Background(), "k1", "v1")
  9. newCtx := NewKVContext(cxt)
  10. newCtx.Set("k2", "v2")
  11. fmt.Println(newCtx.Value("k1"))
  12. fmt.Println(newCtx.Value("k2"))
  13. var cctx context.Context = newCtx
  14. fmt.Println(AssertKVContext(cctx).Get("k2"))
  15. }
  16. func BenchmarkName(b *testing.B) {
  17. for i := 0; i < b.N; i++ {
  18. newCtx := NewKVContext(context.Background())
  19. newCtx.Set("k2", "v2")
  20. newCtx.Value("k2")
  21. }
  22. }