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

Function testNativeEnv

ext/native_test.go:1275–1308  ·  view source on GitHub ↗

testEnv initializes the test environment common to all tests.

(t testing.TB, opts ...any)

Source from the content-addressed store, hash-verified

1273
1274// testEnv initializes the test environment common to all tests.
1275func testNativeEnv(t testing.TB, opts ...any) *cel.Env {
1276 t.Helper()
1277 envOpts := []cel.EnvOption{
1278 cel.Container("ext"),
1279 cel.Abbrevs("google.expr.proto3.test"),
1280 cel.Types(&proto3pb.TestAllTypes{}),
1281 cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))),
1282 }
1283 nativeOpts := []any{
1284 reflect.ValueOf(&TestAllTypes{}),
1285 reflect.ValueOf(&TestRefValFieldType{}),
1286 }
1287 for _, o := range opts {
1288 switch opt := o.(type) {
1289 case NativeTypesOption:
1290 nativeOpts = append(nativeOpts, opt)
1291 case cel.EnvOption:
1292 envOpts = append(envOpts, opt)
1293 default:
1294 t.Fatalf("invalid option type: %s", reflect.TypeOf(o).Name())
1295 }
1296 }
1297
1298 envOpts = append(envOpts,
1299 NativeTypes(
1300 nativeOpts...,
1301 ),
1302 )
1303 env, err := cel.NewEnv(envOpts...)
1304 if err != nil {
1305 t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err)
1306 }
1307 return env
1308}
1309
1310func mustParseTime(t *testing.T, timestamp string) time.Time {
1311 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