@@ -274,16 +274,18 @@ func parseAndCompilePolicy(t testing.TB, name string, policySource string, envOp
274274 return env , ast , iss
275275}
276276
277- func newRunner (name , expr string , parseOpts []ParserOption , opts ... cel.EnvOption ) * runner {
277+ func newRunner (name , expr string , parseOpts []ParserOption , envOpts ... cel.EnvOption ) * runner {
278278 return & runner {
279279 name : name ,
280280 parseOpts : parseOpts ,
281+ envOpts : envOpts ,
281282 expr : expr }
282283}
283284
284285type runner struct {
285286 name string
286287 parseOpts []ParserOption
288+ envOpts []cel.EnvOption
287289 env * cel.Env
288290 expr string
289291 prg cel.Program
@@ -306,6 +308,12 @@ func (r *runner) compileRule(t testing.TB) (*cel.Env, *CompiledRule, *cel.Issues
306308 if err != nil {
307309 t .Fatalf ("cel.NewEnv() failed: %v" , err )
308310 }
311+ if len (r .envOpts ) > 0 {
312+ env , err = env .Extend (r .envOpts ... )
313+ if err != nil {
314+ t .Fatalf ("env.Extend() with env options failed: %v" , err )
315+ }
316+ }
309317 // Configure declarations
310318 env , err = env .Extend (FromConfig (config ))
311319 if err != nil {
@@ -621,9 +629,9 @@ func TestCompileYAMLPolicy_Aggregate(t *testing.T) {
621629rule:
622630 aggregate:
623631 - condition: 'true'
624- emit : '"PII"'
632+ output : '"PII"'
625633 - condition: 'true'
626- emit : '"CONFIDENTIAL"'` ,
634+ output : '"CONFIDENTIAL"'` ,
627635 expectedUnparsed : `["PII"] + ["CONFIDENTIAL"]` ,
628636 evals : []testEval {
629637 {
@@ -643,9 +651,9 @@ rule:
643651 expression: '"CONFIDENTIAL"'
644652 aggregate:
645653 - condition: 'true'
646- emit : 'variables.val1'
654+ output : 'variables.val1'
647655 - condition: 'true'
648- emit : 'variables.val2'` ,
656+ output : 'variables.val2'` ,
649657 expectedUnparsed : `cel.@block(["PII", "CONFIDENTIAL"], [@index0] + [@index1])` ,
650658 evals : []testEval {
651659 {
@@ -663,11 +671,11 @@ rule:
663671 expression: "5"
664672 aggregate:
665673 - condition: "size(resource.payload) > variables.threshold"
666- emit : '"CSE1"'
674+ output : '"CSE1"'
667675 - condition: "size(resource.payload) > variables.threshold"
668- emit : '"CSE2"'
676+ output : '"CSE2"'
669677 - condition: 'true'
670- emit : '"ALWAYS"'` ,
678+ output : '"ALWAYS"'` ,
671679 envOpts : []cel.EnvOption {
672680 cel .Variable ("resource" , cel .MapType (cel .StringType , cel .ListType (cel .IntType ))),
673681 },
@@ -705,7 +713,7 @@ rule:
705713 - condition: "true"
706714 output: "payload.filter(x, x > variables.min_val).exists(y, y % 2 == 0)"
707715 - condition: "true"
708- emit : "payload.all(x, x > 0)"` ,
716+ output : "payload.all(x, x > 0)"` ,
709717 envOpts : []cel.EnvOption {
710718 cel .Variable ("cond" , cel .BoolType ),
711719 cel .Variable ("payload" , cel .ListType (cel .IntType )),
@@ -721,7 +729,7 @@ rule:
721729 rule:
722730 aggregate:
723731 - condition: 'true'
724- emit : "'foo'"` ,
732+ output : "'foo'"` ,
725733 wantErr : "nested aggregate rules are not allowed" ,
726734 },
727735 {
@@ -736,7 +744,7 @@ rule:
736744 rule:
737745 aggregate:
738746 - condition: 'true'
739- emit : "'foo'"` ,
747+ output : "'foo'"` ,
740748 wantErr : "nested aggregate rules are not allowed" ,
741749 },
742750 {
@@ -748,7 +756,7 @@ rule:
748756 rule:
749757 aggregate:
750758 - condition: 'true'
751- emit : "'foo'"` ,
759+ output : "'foo'"` ,
752760 expectedUnparsed : `["foo"]` ,
753761 },
754762 }
@@ -807,7 +815,7 @@ func TestCompiledRuleSemantic(t *testing.T) {
807815rule:
808816 aggregate:
809817 - condition: 'true'
810- emit : "'foo'"`
818+ output : "'foo'"`
811819 policy := parsePolicySource (t , "aggregate_semantic" , policySource )
812820 env , err := cel .NewEnv ()
813821 if err != nil {
@@ -827,7 +835,7 @@ func TestCompileYAMLPolicy_ConditionAlwaysFalse(t *testing.T) {
827835rule:
828836 aggregate:
829837 - condition: 'false'
830- emit : "'foo'"`
838+ output : "'foo'"`
831839 _ , _ , iss := parseAndCompilePolicy (t , "condition_always_false" , policySource , nil , nil )
832840 if iss .Err () == nil {
833841 t .Fatalf ("Compile() succeeded, wanted error" )
0 commit comments