@@ -48,15 +48,14 @@ func (t *testVariable) GetName() string {
4848
4949func TestCompositedPolicies (t * testing.T ) {
5050cases := []struct {
51- name string
52- variables []NamedExpressionAccessor
53- expression string
54- attributes admission.Attributes
55- expectedResult any
56- expectErr bool
57- expectedErrorMessage string
58- runtimeCostBudget int64
59- strictCostEnforcement bool
51+ name string
52+ variables []NamedExpressionAccessor
53+ expression string
54+ attributes admission.Attributes
55+ expectedResult any
56+ expectErr bool
57+ expectedErrorMessage string
58+ runtimeCostBudget int64
6059}{
6160{
6261name : "simple" ,
@@ -187,44 +186,29 @@ func TestCompositedPolicies(t *testing.T) {
187186expectedErrorMessage : "found no matching overload for '_==_' applied to '(string, int)'" ,
188187},
189188{
190- name : "with strictCostEnforcement on: exceeds cost budget" ,
189+ name : "exceeds cost budget" ,
191190variables : []NamedExpressionAccessor {
192191& testVariable {
193192name : "dict" ,
194193expression : "'abc 123 def 123'.split(' ')" ,
195194},
196195},
197- attributes : endpointCreateAttributes (),
198- expression : "size(variables.dict) > 0" ,
199- expectErr : true ,
200- expectedErrorMessage : "validation failed due to running out of cost budget, no further validation rules will be run" ,
201- runtimeCostBudget : 5 ,
202- strictCostEnforcement : true ,
203- },
204- {
205- name : "with strictCostEnforcement off: not exceed cost budget" ,
206- variables : []NamedExpressionAccessor {
207- & testVariable {
208- name : "dict" ,
209- expression : "'abc 123 def 123'.split(' ')" ,
210- },
211- },
212- attributes : endpointCreateAttributes (),
213- expression : "size(variables.dict) > 0" ,
214- expectedResult : true ,
215- runtimeCostBudget : 5 ,
216- strictCostEnforcement : false ,
196+ attributes : endpointCreateAttributes (),
197+ expression : "size(variables.dict) > 0" ,
198+ expectErr : true ,
199+ expectedErrorMessage : "validation failed due to running out of cost budget, no further validation rules will be run" ,
200+ runtimeCostBudget : 5 ,
217201},
218202}
219203for _ , tc := range cases {
220204t .Run (tc .name , func (t * testing.T ) {
221- compiler , err := NewCompositedCompiler (environment .MustBaseEnvSet (environment .DefaultCompatibilityVersion (), tc . strictCostEnforcement ))
205+ compiler , err := NewCompositedCompiler (environment .MustBaseEnvSet (environment .DefaultCompatibilityVersion ()))
222206if err != nil {
223207t .Fatal (err )
224208}
225- compiler .CompileAndStoreVariables (tc .variables , OptionalVariableDeclarations {HasParams : false , HasAuthorizer : false , StrictCost : tc . strictCostEnforcement }, environment .NewExpressions )
209+ compiler .CompileAndStoreVariables (tc .variables , OptionalVariableDeclarations {HasParams : false , HasAuthorizer : false }, environment .NewExpressions )
226210validations := []ExpressionAccessor {& testCondition {Expression : tc .expression }}
227- f := compiler .CompileCondition (validations , OptionalVariableDeclarations {HasParams : false , HasAuthorizer : false , StrictCost : tc . strictCostEnforcement }, environment .NewExpressions )
211+ f := compiler .CompileCondition (validations , OptionalVariableDeclarations {HasParams : false , HasAuthorizer : false }, environment .NewExpressions )
228212versionedAttr , err := admission .NewVersionedAttributes (tc .attributes , tc .attributes .GetKind (), newObjectInterfacesForTest ())
229213if err != nil {
230214t .Fatal (err )
0 commit comments