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

Function testNativeEnv

ext/native_test.go:1499–1532  ·  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

1497
1498// testEnv initializes the test environment common to all tests.
1499func testNativeEnv(t testing.TB, opts ...any) *cel.Env {
1500 t.Helper()
1501 envOpts := []cel.EnvOption{
1502 cel.Container("ext"),
1503 cel.Abbrevs("google.expr.proto3.test"),
1504 cel.Types(&proto3pb.TestAllTypes{}),
1505 cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))),
1506 }
1507 nativeOpts := []any{
1508 reflect.ValueOf(&TestAllTypes{}),
1509 reflect.ValueOf(&TestRefValFieldType{}),
1510 }
1511 for _, o := range opts {
1512 switch opt := o.(type) {
1513 case NativeTypesOption:
1514 nativeOpts = append(nativeOpts, opt)
1515 case cel.EnvOption:
1516 envOpts = append(envOpts, opt)
1517 default:
1518 t.Fatalf("invalid option type: %s", reflect.TypeOf(o).Name())
1519 }
1520 }
1521
1522 envOpts = append(envOpts,
1523 NativeTypes(
1524 nativeOpts...,
1525 ),
1526 )
1527 env, err := cel.NewEnv(envOpts...)
1528 if err != nil {
1529 t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err)
1530 }
1531 return env
1532}
1533
1534func mustParseTime(t *testing.T, timestamp string) time.Time {
1535 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