(t *testing.T)
| 930 | } |
| 931 | |
| 932 | func TestNativeStructEmbedded(t *testing.T) { |
| 933 | var nativeTests = []struct { |
| 934 | expr string |
| 935 | in any |
| 936 | }{ |
| 937 | { |
| 938 | expr: `test.embedded.custom_name == "name"`, |
| 939 | in: map[string]any{ |
| 940 | "test": &TestEmbeddedTypes{TestNestedType{NestedCustomName: "name"}}, |
| 941 | }, |
| 942 | }, |
| 943 | } |
| 944 | |
| 945 | envOpts := []cel.EnvOption{ |
| 946 | NativeTypes( |
| 947 | reflect.TypeOf(&TestEmbeddedTypes{}), |
| 948 | reflect.TypeOf(&TestNestedType{}), |
| 949 | ParseStructTag("json"), |
| 950 | ), |
| 951 | cel.Variable("test", cel.ObjectType("ext.TestEmbeddedTypes")), |
| 952 | } |
| 953 | |
| 954 | env, err := cel.NewEnv(envOpts...) |
| 955 | if err != nil { |
| 956 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 957 | } |
| 958 | |
| 959 | for i, tst := range nativeTests { |
| 960 | tc := tst |
| 961 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 962 | var asts []*cel.Ast |
| 963 | pAst, iss := env.Parse(tc.expr) |
| 964 | if iss.Err() != nil { |
| 965 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 966 | } |
| 967 | asts = append(asts, pAst) |
| 968 | cAst, iss := env.Check(pAst) |
| 969 | if iss.Err() != nil { |
| 970 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 971 | } |
| 972 | asts = append(asts, cAst) |
| 973 | for _, ast := range asts { |
| 974 | prg, err := env.Program(ast) |
| 975 | if err != nil { |
| 976 | t.Fatal(err) |
| 977 | } |
| 978 | out, _, err := prg.Eval(tc.in) |
| 979 | if err != nil { |
| 980 | t.Fatal(err) |
| 981 | } |
| 982 | if !reflect.DeepEqual(out.Value(), true) { |
| 983 | t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 984 | } |
| 985 | } |
| 986 | }) |
| 987 | } |
| 988 | } |
| 989 |
nothing calls this directly
no test coverage detected