mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
Add cel new validator into Kubernetes.
This commit is contained in:
parent
af52a7052b
commit
04b21126e5
@ -274,7 +274,7 @@ func TestValidationExpressions(t *testing.T) {
|
||||
},
|
||||
errors: map[string]string{
|
||||
// Invalid regex with a string constant regex pattern is compile time error
|
||||
"self.val1.matches(')')": "compile error: program instantiation failed: error parsing regexp: unexpected ): `)`",
|
||||
"self.val1.matches(')')": "compile error: compilation failed: ERROR: <input>:1:19: invalid matches argument",
|
||||
},
|
||||
},
|
||||
{name: "escaped strings",
|
||||
@ -319,6 +319,11 @@ func TestValidationExpressions(t *testing.T) {
|
||||
"self.val1.getMilliseconds() == 3723004",
|
||||
"type(self.val1) == google.protobuf.Duration",
|
||||
},
|
||||
errors: map[string]string{
|
||||
"duration('1')": "invalid duration argument",
|
||||
"duration('1d')": "invalid duration argument",
|
||||
"duration('1us') < duration('1nns')": "invalid duration argument",
|
||||
},
|
||||
},
|
||||
{name: "date format",
|
||||
obj: objs("1997-07-16", "1997-07-16"),
|
||||
@ -347,6 +352,11 @@ func TestValidationExpressions(t *testing.T) {
|
||||
"self.val1.getHours('UTC') == 18", // TZ in string is 1hr off of UTC
|
||||
"type(self.val1) == google.protobuf.Timestamp",
|
||||
},
|
||||
errors: map[string]string{
|
||||
"timestamp('1000-00-00T00:00:00Z')": "invalid timestamp",
|
||||
"timestamp('1000-01-01T00:00:00ZZ')": "invalid timestamp",
|
||||
"timestamp(-62135596801)": "invalid timestamp",
|
||||
},
|
||||
},
|
||||
{name: "enums",
|
||||
obj: map[string]interface{}{"enumStr": "Pending"},
|
||||
@ -1747,6 +1757,7 @@ func TestValidationExpressions(t *testing.T) {
|
||||
"self.str.find(')') == ''": "compile error: program instantiation failed: error parsing regexp: unexpected ): `)`",
|
||||
"self.str.findAll(')') == []": "compile error: program instantiation failed: error parsing regexp: unexpected ): `)`",
|
||||
"self.str.findAll(')', 1) == []": "compile error: program instantiation failed: error parsing regexp: unexpected ): `)`",
|
||||
"self.str.matches('x++')": "invalid matches argument",
|
||||
},
|
||||
},
|
||||
{name: "URL parsing",
|
||||
|
@ -80,7 +80,18 @@ var baseOpts = []VersionedOptions{
|
||||
library.Quantity(),
|
||||
},
|
||||
},
|
||||
|
||||
// add the new validator in 1.29
|
||||
{
|
||||
IntroducedVersion: version.MajorMinor(1, 29),
|
||||
EnvOptions: []cel.EnvOption{
|
||||
cel.ASTValidators(
|
||||
cel.ValidateDurationLiterals(),
|
||||
cel.ValidateTimestampLiterals(),
|
||||
cel.ValidateRegexLiterals(),
|
||||
cel.ValidateHomogeneousAggregateLiterals(),
|
||||
),
|
||||
},
|
||||
},
|
||||
// String library
|
||||
{
|
||||
IntroducedVersion: version.MajorMinor(1, 0),
|
||||
|
Loading…
Reference in New Issue
Block a user