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

Function TestCompileYAMLPolicy_Aggregate

policy/compiler_test.go:620–824  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

618}
619
620func TestCompileYAMLPolicy_Aggregate(t *testing.T) {
621 type testEval struct {
622 input map[string]any
623 output ref.Val
624 }
625 tests := []struct {
626 name string
627 policy string
628 envOpts []cel.EnvOption
629 expectedUnparsed string
630 evals []testEval
631 wantErr string
632 }{
633 {
634 name: "eval_aggregate",
635 policy: `name: "aggregate_policy"
636rule:
637 aggregate:
638 - condition: 'true'
639 output: '"PII"'
640 - condition: 'true'
641 output: '"CONFIDENTIAL"'`,
642 expectedUnparsed: `["PII"] + ["CONFIDENTIAL"]`,
643 evals: []testEval{
644 {
645 input: map[string]any{},
646 output: types.NewStringList(types.DefaultTypeAdapter, []string{"PII", "CONFIDENTIAL"}),
647 },
648 },
649 },
650 {
651 name: "aggregate_with_block_variables",
652 policy: `name: "block_policy"
653rule:
654 variables:
655 - name: val1
656 expression: '"PII"'
657 - name: val2
658 expression: '"CONFIDENTIAL"'
659 aggregate:
660 - condition: 'true'
661 output: 'variables.val1'
662 - condition: 'true'
663 output: 'variables.val2'`,
664 expectedUnparsed: `cel.@block(["PII", "CONFIDENTIAL"], [@index0] + [@index1])`,
665 evals: []testEval{
666 {
667 input: map[string]any{},
668 output: types.NewStringList(types.DefaultTypeAdapter, []string{"PII", "CONFIDENTIAL"}),
669 },
670 },
671 },
672 {
673 name: "aggregate_conditions_and_block_variables",
674 policy: `name: "cse_policy"
675rule:
676 variables:
677 - name: threshold

Callers

nothing calls this directly

Calls 15

NewStringListFunction · 0.92
VariableFunction · 0.92
AstToStringFunction · 0.92
AstToCheckedExprFunction · 0.92
parseAndCompilePolicyFunction · 0.85
ErrMethod · 0.80
HasExtensionMethod · 0.80
NativeRepMethod · 0.80
ProgramMethod · 0.80
normalizeFunction · 0.70
ContainsMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected