@@ -7282,7 +7282,7 @@ func TestValidateCustomResourceDefinitionUpdate(t *testing.T) {
7282
7282
}
7283
7283
7284
7284
func TestValidateCustomResourceDefinitionValidationRuleCompatibility (t * testing.T ) {
7285
- allValidationsErrors := []validationMatch {
7285
+ allRuleValidationsErrors := []validationMatch {
7286
7286
invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[x]" , "x-kubernetes-validations[0]" , "rule" ),
7287
7287
invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[obj]" , "x-kubernetes-validations[0]" , "rule" ),
7288
7288
invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[obj]" , "properties[a]" , "x-kubernetes-validations[0]" , "rule" ),
@@ -7291,23 +7291,46 @@ func TestValidateCustomResourceDefinitionValidationRuleCompatibility(t *testing.
7291
7291
invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[map]" , "x-kubernetes-validations[0]" , "rule" ),
7292
7292
invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[map]" , "additionalProperties" , "x-kubernetes-validations[0]" , "rule" ),
7293
7293
}
7294
+ allMessageExpressionValidationsErrors := []validationMatch {
7295
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[x]" , "x-kubernetes-validations[0]" , "messageExpression" ),
7296
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[obj]" , "x-kubernetes-validations[0]" , "messageExpression" ),
7297
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[obj]" , "properties[a]" , "x-kubernetes-validations[0]" , "messageExpression" ),
7298
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[array]" , "x-kubernetes-validations[0]" , "messageExpression" ),
7299
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[array]" , "items" , "x-kubernetes-validations[0]" , "messageExpression" ),
7300
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[map]" , "x-kubernetes-validations[0]" , "messageExpression" ),
7301
+ invalid ("spec" , "validation" , "openAPIV3Schema" , "properties[map]" , "additionalProperties" , "x-kubernetes-validations[0]" , "messageExpression" ),
7302
+ }
7294
7303
7295
7304
tests := []struct {
7296
- name string
7297
- storedRule string
7298
- updatedRule string
7299
- errors []validationMatch
7305
+ name string
7306
+ storedRule string
7307
+ updatedRule string
7308
+ storedMessageExpression string
7309
+ updatedMessageExpression string
7310
+ errors []validationMatch
7300
7311
}{
7301
7312
{
7302
- name : "functions declared for storage mode allowed if expression is unchanged from what is stored" ,
7303
- storedRule : "test() == true" ,
7304
- updatedRule : "test() == true" ,
7313
+ name : "functions declared for storage mode allowed if expressions are unchanged from what is stored" ,
7314
+ storedRule : "test() == true" ,
7315
+ updatedRule : "test() == true" ,
7316
+ storedMessageExpression : "'test: %s'.format([test()])" ,
7317
+ updatedMessageExpression : "'test: %s'.format([test()])" ,
7318
+ },
7319
+ {
7320
+ name : "functions declared for storage mode not allowed if rule expression is changed" ,
7321
+ storedRule : "test() == false" ,
7322
+ updatedRule : "test() == true" , // rule was changed
7323
+ storedMessageExpression : "'test: %s'.format([test()])" ,
7324
+ updatedMessageExpression : "'test: %s'.format([test()])" ,
7325
+ errors : allRuleValidationsErrors ,
7305
7326
},
7306
7327
{
7307
- name : "functions declared for storage mode not allowed if expression is changed" ,
7308
- storedRule : "test() == false" ,
7309
- updatedRule : "test() == true" ,
7310
- errors : allValidationsErrors ,
7328
+ name : "functions declared for storage mode not allowed if message expression is changed" ,
7329
+ storedRule : "test() == true" ,
7330
+ updatedRule : "test() == true" ,
7331
+ storedMessageExpression : "'test: %s'.format([test()])" ,
7332
+ updatedMessageExpression : "'test - updated: %s'.format([test()])" , // messageExpression was changed
7333
+ errors : allMessageExpressionValidationsErrors ,
7311
7334
},
7312
7335
}
7313
7336
@@ -7322,10 +7345,11 @@ func TestValidateCustomResourceDefinitionValidationRuleCompatibility(t *testing.
7322
7345
}
7323
7346
7324
7347
for _ , tc := range tests {
7325
- fn := func (rule string ) * apiextensions.CustomResourceDefinition {
7348
+ fn := func (rule , messageExpression string ) * apiextensions.CustomResourceDefinition {
7326
7349
validationRules := []apiextensions.ValidationRule {
7327
7350
{
7328
- Rule : rule ,
7351
+ Rule : rule ,
7352
+ MessageExpression : messageExpression ,
7329
7353
},
7330
7354
}
7331
7355
return & apiextensions.CustomResourceDefinition {
@@ -7382,8 +7406,8 @@ func TestValidateCustomResourceDefinitionValidationRuleCompatibility(t *testing.
7382
7406
Status : apiextensions.CustomResourceDefinitionStatus {StoredVersions : []string {"version" }},
7383
7407
}
7384
7408
}
7385
- old := fn (tc .storedRule )
7386
- resource := fn (tc .updatedRule )
7409
+ old := fn (tc .storedRule , tc . storedMessageExpression )
7410
+ resource := fn (tc .updatedRule , tc . updatedMessageExpression )
7387
7411
7388
7412
t .Run (tc .name , func (t * testing.T ) {
7389
7413
ctx := context .TODO ()
0 commit comments