(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestWithContext_with_env_method_chain(t *testing.T) { |
| 98 | env := map[string]any{ |
| 99 | "ctx": context.TODO(), |
| 100 | } |
| 101 | |
| 102 | fn := expr.Function("fn", |
| 103 | func(params ...any) (any, error) { |
| 104 | ctx := params[0].(context.Context) |
| 105 | |
| 106 | contextValue := ctx.Value("value").(int) |
| 107 | |
| 108 | return &TestFoo{ |
| 109 | contextValue: contextValue, |
| 110 | }, nil |
| 111 | }, |
| 112 | new(func(context.Context) *TestFoo), |
| 113 | ) |
| 114 | |
| 115 | program, err := expr.Compile( |
| 116 | `fn().GetValue(40)`, |
| 117 | expr.Env(env), |
| 118 | expr.WithContext("ctx"), |
| 119 | fn, |
| 120 | expr.AsInt64(), |
| 121 | ) |
| 122 | require.NoError(t, err) |
| 123 | |
| 124 | ctx := context.WithValue(context.Background(), "value", 2) |
| 125 | env["ctx"] = ctx |
| 126 | |
| 127 | output, err := expr.Run(program, env) |
| 128 | require.NoError(t, err) |
| 129 | require.Equal(t, int64(42), output) |
| 130 | } |
| 131 | |
| 132 | func TestWithContext_issue529(t *testing.T) { |
| 133 | env := map[string]any{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…