testEnv initializes the test environment common to all tests.
(t *testing.T, opts ...any)
| 1098 | |
| 1099 | // testEnv initializes the test environment common to all tests. |
| 1100 | func testNativeEnv(t *testing.T, opts ...any) *cel.Env { |
| 1101 | t.Helper() |
| 1102 | envOpts := []cel.EnvOption{ |
| 1103 | cel.Container("ext"), |
| 1104 | cel.Abbrevs("google.expr.proto3.test"), |
| 1105 | cel.Types(&proto3pb.TestAllTypes{}), |
| 1106 | cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))), |
| 1107 | } |
| 1108 | nativeOpts := []any{ |
| 1109 | reflect.ValueOf(&TestAllTypes{}), |
| 1110 | reflect.ValueOf(&TestRefValFieldType{}), |
| 1111 | } |
| 1112 | for _, o := range opts { |
| 1113 | switch opt := o.(type) { |
| 1114 | case NativeTypesOption: |
| 1115 | nativeOpts = append(nativeOpts, opt) |
| 1116 | case cel.EnvOption: |
| 1117 | envOpts = append(envOpts, opt) |
| 1118 | default: |
| 1119 | t.Fatalf("invalid option type: %s", reflect.TypeOf(o).Name()) |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | envOpts = append(envOpts, |
| 1124 | NativeTypes( |
| 1125 | nativeOpts..., |
| 1126 | ), |
| 1127 | ) |
| 1128 | env, err := cel.NewEnv(envOpts...) |
| 1129 | if err != nil { |
| 1130 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1131 | } |
| 1132 | return env |
| 1133 | } |
| 1134 | |
| 1135 | func mustParseTime(t *testing.T, timestamp string) time.Time { |
| 1136 | t.Helper() |
no test coverage detected