fix(types): make UnwrapSDKContext work after context.WithValue (#11341)

This commit is contained in:
Aaron Craelius 2022-03-11 14:49:17 -05:00 committed by GitHub
parent f4d50a989f
commit 25feb237f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -237,6 +237,10 @@ func (c Context) WithValue(key, value interface{}) Context {
}
func (c Context) Value(key interface{}) interface{} {
if key == SdkContextKey {
return c
}
return c.baseCtx.Value(key)
}

View File

@ -220,4 +220,9 @@ func (s *contextTestSuite) TestUnwrapSDKContext() {
ctx = context.Background()
s.Require().Panics(func() { types.UnwrapSDKContext(ctx) })
// test unwrapping when we've used context.WithValue
ctx = context.WithValue(sdkCtx, "foo", "bar")
sdkCtx2 = types.UnwrapSDKContext(ctx)
s.Require().Equal(sdkCtx, sdkCtx2)
}