(t *testing.T, testCase *test.Case)
| 898 | } |
| 899 | |
| 900 | func (tr *TestRunner) createTestInput(t *testing.T, testCase *test.Case) (cel.PartialActivation, error) { |
| 901 | t.Helper() |
| 902 | e, err := tr.CreateEnv() |
| 903 | if err != nil { |
| 904 | return nil, err |
| 905 | } |
| 906 | var activation cel.Activation |
| 907 | if testCase.InputContext != nil && testCase.InputContext.ContextExpr != "" { |
| 908 | if len(testCase.Input) != 0 { |
| 909 | return nil, fmt.Errorf("only one of input and input_context can be provided at a time") |
| 910 | } |
| 911 | contextExpr := testCase.InputContext.ContextExpr |
| 912 | out, err := tr.eval(contextExpr) |
| 913 | if err != nil { |
| 914 | return nil, fmt.Errorf("eval(%q) failed: %w", contextExpr, err) |
| 915 | } |
| 916 | ctx, err := out.ConvertToNative(reflect.TypeOf((*proto.Message)(nil)).Elem()) |
| 917 | if err != nil { |
| 918 | return nil, fmt.Errorf("context variable is not a valid proto: %w", err) |
| 919 | } |
| 920 | activation, err = cel.ContextProtoVars(ctx.(proto.Message)) |
| 921 | if err != nil { |
| 922 | return nil, fmt.Errorf("cel.ContextProtoVars() failed: %w", err) |
| 923 | } |
| 924 | return e.PartialVars(activation) |
| 925 | } |
| 926 | input := map[string]any{} |
| 927 | for k, v := range testCase.Input { |
| 928 | if v.Expr != "" { |
| 929 | val, err := tr.eval(v.Expr) |
| 930 | if err != nil { |
| 931 | return nil, fmt.Errorf("eval(%q) failed: %w", v.Expr, err) |
| 932 | } |
| 933 | input[k] = val |
| 934 | continue |
| 935 | } |
| 936 | input[k] = v.Value |
| 937 | } |
| 938 | activation, err = tr.activationFactory(input) |
| 939 | if err != nil { |
| 940 | return nil, fmt.Errorf("activationFactory(%q) failed: %w", input, err) |
| 941 | } |
| 942 | return e.PartialVars(activation) |
| 943 | } |
| 944 | |
| 945 | func (tr *TestRunner) createResultMatcher(t *testing.T, testOutput *test.Output) (func(ref.Val, error) TestResult, error) { |
| 946 | t.Helper() |
no test coverage detected