testEnv initializes the test environment common to all tests.
(t *testing.T, opts ...any)
| 1169 | |
| 1170 | // testEnv initializes the test environment common to all tests. |
| 1171 | func testNativeEnv(t *testing.T, opts ...any) *cel.Env { |
| 1172 | t.Helper() |
| 1173 | envOpts := []cel.EnvOption{ |
| 1174 | cel.Container("ext"), |
| 1175 | cel.Abbrevs("google.expr.proto3.test"), |
| 1176 | cel.Types(&proto3pb.TestAllTypes{}), |
| 1177 | cel.Variable("tests", cel.ListType(cel.ObjectType("ext.TestAllTypes"))), |
| 1178 | } |
| 1179 | nativeOpts := []any{ |
| 1180 | reflect.ValueOf(&TestAllTypes{}), |
| 1181 | reflect.ValueOf(&TestRefValFieldType{}), |
| 1182 | } |
| 1183 | for _, o := range opts { |
| 1184 | switch opt := o.(type) { |
| 1185 | case NativeTypesOption: |
| 1186 | nativeOpts = append(nativeOpts, opt) |
| 1187 | case cel.EnvOption: |
| 1188 | envOpts = append(envOpts, opt) |
| 1189 | default: |
| 1190 | t.Fatalf("invalid option type: %s", reflect.TypeOf(o).Name()) |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | envOpts = append(envOpts, |
| 1195 | NativeTypes( |
| 1196 | nativeOpts..., |
| 1197 | ), |
| 1198 | ) |
| 1199 | env, err := cel.NewEnv(envOpts...) |
| 1200 | if err != nil { |
| 1201 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1202 | } |
| 1203 | return env |
| 1204 | } |
| 1205 | |
| 1206 | func mustParseTime(t *testing.T, timestamp string) time.Time { |
| 1207 | t.Helper() |
no test coverage detected