github.com/kaiya/goutils@v1.0.1-0.20230226104005-4ae4a4dc3688/kvctx/kvctx_test.go (about) 1 package kvctx 2 3 import ( 4 "context" 5 "testing" 6 ) 7 8 func Test_valueCtx(t *testing.T) { 9 10 tests := []struct { 11 name string 12 key string 13 value float64 14 want float64 15 }{ 16 { 17 "pass-float", 18 "str-key", 19 10.0, 20 10.0, 21 }, 22 } 23 24 for _, tt := range tests { 25 t.Run(tt.name, func(t *testing.T) { 26 ctx := WithContext(context.Background()) 27 Add(ctx, tt.key, tt.value) 28 v := Get(ctx, tt.key) 29 value, ok := v.(float64) 30 if !ok { 31 t.Errorf("got value from context, result: %v, want %v", value, tt.want) 32 } 33 }) 34 } 35 }