testEnv initializes the test environment common to all tests.
(t testing.TB, opts ...any)
| 1497 | |
| 1498 | // testEnv initializes the test environment common to all tests. |
| 1499 | func 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 | |
| 1534 | func mustParseTime(t *testing.T, timestamp string) time.Time { |
| 1535 | t.Helper() |
no test coverage detected