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

Function TestCompileYAMLPolicy_Aggregate

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

NewStringListFunction · 0.92
VariableFunction · 0.92
AstToStringFunction · 0.92
AstToCheckedExprFunction · 0.92
parseAndCompilePolicyFunction · 0.85
normalizeFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
ContainsMethod · 0.65
EvalMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected