MCPcopy
hub / github.com/expr-lang/expr / TestWithContext_with_env_method_chain

Function TestWithContext_with_env_method_chain

patcher/with_context_test.go:97–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func 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
132func TestWithContext_issue529(t *testing.T) {
133 env := map[string]any{

Callers

nothing calls this directly

Calls 8

FunctionFunction · 0.92
CompileFunction · 0.92
EnvStruct · 0.92
WithContextFunction · 0.92
AsInt64Function · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…