github.com/xmidt-org/webpa-common@v1.11.9/convey/context_test.go (about) 1 package convey 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestNewContext(t *testing.T) { 11 var ( 12 assert = assert.New(t) 13 ctx = NewContext(context.Background(), C{"foo": "bar"}) 14 ) 15 16 assert.Equal(C{"foo": "bar"}, ctx.Value(contextKey{})) 17 } 18 19 func TestFromContext(t *testing.T) { 20 var ( 21 assert = assert.New(t) 22 ctx = context.Background() 23 ) 24 25 v, ok := FromContext(ctx) 26 assert.Empty(v) 27 assert.False(ok) 28 29 ctx = context.WithValue(ctx, contextKey{}, C{"foo": "bar"}) 30 v, ok = FromContext(ctx) 31 assert.Equal(C{"foo": "bar"}, v) 32 assert.True(ok) 33 }