MCPcopy Create free account
hub / github.com/cel-expr/cel-go / testNativeEnv

Function testNativeEnv

ext/native_test.go:1171–1204  ·  view source on GitHub ↗

testEnv initializes the test environment common to all tests.

(t *testing.T, opts ...any)

Source from the content-addressed store, hash-verified

1169
1170// testEnv initializes the test environment common to all tests.
1171func testNativeEnv(t *testing.T, opts ...any) *cel.Env {
1172 t.Helper()
1173 envOpts := []cel.EnvOption{
1174 cel.Container("ext"),
1175 cel.Abbrevs("google.expr.proto3.test"),
1176 cel.Types(&proto3pb.TestAllTypes{}),
1177 cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))),
1178 }
1179 nativeOpts := []any{
1180 reflect.ValueOf(&TestAllTypes{}),
1181 reflect.ValueOf(&TestRefValFieldType{}),
1182 }
1183 for _, o := range opts {
1184 switch opt := o.(type) {
1185 case NativeTypesOption:
1186 nativeOpts = append(nativeOpts, opt)
1187 case cel.EnvOption:
1188 envOpts = append(envOpts, opt)
1189 default:
1190 t.Fatalf("invalid option type: %s", reflect.TypeOf(o).Name())
1191 }
1192 }
1193
1194 envOpts = append(envOpts,
1195 NativeTypes(
1196 nativeOpts...,
1197 ),
1198 )
1199 env, err := cel.NewEnv(envOpts...)
1200 if err != nil {
1201 t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err)
1202 }
1203 return env
1204}
1205
1206func mustParseTime(t *testing.T, timestamp string) time.Time {
1207 t.Helper()

Calls 7

ContainerFunction · 0.92
AbbrevsFunction · 0.92
TypesFunction · 0.92
VariableFunction · 0.92
NewEnvFunction · 0.92
NativeTypesFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected