(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func TestWithContext_with_env_Function(t *testing.T) { |
| 35 | env := map[string]any{ |
| 36 | "ctx": context.TODO(), |
| 37 | } |
| 38 | |
| 39 | fn := expr.Function("fn", |
| 40 | func(params ...any) (any, error) { |
| 41 | ctx := params[0].(context.Context) |
| 42 | a := params[1].(int) |
| 43 | |
| 44 | return ctx.Value("value").(int) + a, nil |
| 45 | }, |
| 46 | new(func(context.Context, int) int), |
| 47 | ) |
| 48 | |
| 49 | program, err := expr.Compile( |
| 50 | `fn(40)`, |
| 51 | expr.Env(env), |
| 52 | expr.WithContext("ctx"), |
| 53 | fn, |
| 54 | ) |
| 55 | require.NoError(t, err) |
| 56 | |
| 57 | ctx := context.WithValue(context.Background(), "value", 2) |
| 58 | env["ctx"] = ctx |
| 59 | |
| 60 | output, err := expr.Run(program, env) |
| 61 | require.NoError(t, err) |
| 62 | require.Equal(t, 42, output) |
| 63 | } |
| 64 | |
| 65 | type testEnvContext struct { |
| 66 | Context context.Context `expr:"ctx"` |
nothing calls this directly
no test coverage detected
searching dependent graphs…