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

Function testNativeEnv

ext/native_test.go:1100–1133  ·  view source on GitHub ↗

testEnv initializes the test environment common to all tests.

(t *testing.T, opts ...any)

Source from the content-addressed store, hash-verified

1098
1099// testEnv initializes the test environment common to all tests.
1100func 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
1135func mustParseTime(t *testing.T, timestamp string) time.Time {
1136 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