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