@@ -184,6 +184,7 @@ func TestCondition(t *testing.T) {
184
184
185
185
v130 := version .MajorMinor (1 , 30 )
186
186
v131 := version .MajorMinor (1 , 31 )
187
+ v127 := version .MajorMinor (1 , 27 )
187
188
188
189
var nilUnstructured * unstructured.Unstructured
189
190
cases := []struct {
@@ -200,6 +201,7 @@ func TestCondition(t *testing.T) {
200
201
enableSelectors bool
201
202
202
203
compatibilityVersion * version.Version
204
+ envType environment.Type
203
205
}{
204
206
{
205
207
name : "valid syntax for object" ,
@@ -867,6 +869,52 @@ func TestCondition(t *testing.T) {
867
869
hasParamKind : false ,
868
870
namespaceObject : nsObject ,
869
871
},
872
+ {
873
+ name : "cel lib not recognized in version earlier than introduced version" ,
874
+ validations : []ExpressionAccessor {
875
+ & testCondition {
876
+ Expression : "isQuantity(\" 20M\" )" ,
877
+ },
878
+ },
879
+ attributes : newValidAttribute (& podObject , false ),
880
+ results : []EvaluationResult {
881
+ {
882
+ Error : fmt .Errorf ("isQuantity" ),
883
+ },
884
+ },
885
+ compatibilityVersion : v127 ,
886
+ },
887
+ {
888
+ name : "cel lib recognized in version later than introduced version" ,
889
+ validations : []ExpressionAccessor {
890
+ & testCondition {
891
+ Expression : "isQuantity(\" 20M\" )" ,
892
+ },
893
+ },
894
+ results : []EvaluationResult {
895
+ {
896
+ EvalResult : celtypes .True ,
897
+ },
898
+ },
899
+ attributes : newValidAttribute (& podObject , false ),
900
+ compatibilityVersion : v130 ,
901
+ },
902
+ {
903
+ name : "cel lib always recognized in stored expression" ,
904
+ validations : []ExpressionAccessor {
905
+ & testCondition {
906
+ Expression : "isQuantity(\" 20M\" )" ,
907
+ },
908
+ },
909
+ attributes : newValidAttribute (& podObject , false ),
910
+ results : []EvaluationResult {
911
+ {
912
+ EvalResult : celtypes .True ,
913
+ },
914
+ },
915
+ envType : environment .StoredExpressions ,
916
+ compatibilityVersion : version .MajorMinor (1 , 2 ),
917
+ },
870
918
}
871
919
872
920
for _ , tc := range cases {
@@ -891,7 +939,11 @@ func TestCondition(t *testing.T) {
891
939
t .Fatal (err )
892
940
}
893
941
c := NewConditionCompiler (env )
894
- f := c .CompileCondition (tc .validations , OptionalVariableDeclarations {HasParams : tc .hasParamKind , HasAuthorizer : tc .authorizer != nil , StrictCost : tc .strictCost }, environment .NewExpressions )
942
+ envType := tc .envType
943
+ if envType == "" {
944
+ envType = environment .NewExpressions
945
+ }
946
+ f := c .CompileCondition (tc .validations , OptionalVariableDeclarations {HasParams : tc .hasParamKind , HasAuthorizer : tc .authorizer != nil , StrictCost : tc .strictCost }, envType )
895
947
if f == nil {
896
948
t .Fatalf ("unexpected nil validator" )
897
949
}
0 commit comments