mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Update err handling
This commit is contained in:
parent
383eb99beb
commit
c6d4b14730
@ -85,24 +85,32 @@ func ValidateCustomResource(fldPath *field.Path, customResource interface{}, val
|
||||
value = err.Value
|
||||
}
|
||||
max := int64(-1)
|
||||
if i, ok := err.Value.(int64); ok {
|
||||
if i, ok := err.Valid.(int64); ok {
|
||||
max = i
|
||||
}
|
||||
allErrs = append(allErrs, field.TooLongMaxLength(errPath, value, int(max)))
|
||||
|
||||
case openapierrors.MaxItemsFailCode:
|
||||
max := int64(-1)
|
||||
actual := int64(-1)
|
||||
if i, ok := err.Value.(int64); ok {
|
||||
actual = i
|
||||
}
|
||||
max := int64(-1)
|
||||
if i, ok := err.Valid.(int64); ok {
|
||||
max = i
|
||||
}
|
||||
allErrs = append(allErrs, field.TooMany(errPath, int(max), -1))
|
||||
allErrs = append(allErrs, field.TooMany(errPath, int(actual), int(max)))
|
||||
|
||||
case openapierrors.TooManyPropertiesCode:
|
||||
max := int64(-1)
|
||||
actual := int64(-1)
|
||||
if i, ok := err.Value.(int64); ok {
|
||||
actual = i
|
||||
}
|
||||
max := int64(-1)
|
||||
if i, ok := err.Valid.(int64); ok {
|
||||
max = i
|
||||
}
|
||||
allErrs = append(allErrs, field.TooMany(errPath, -1, int(max)))
|
||||
allErrs = append(allErrs, field.TooMany(errPath, int(actual), int(max)))
|
||||
|
||||
case openapierrors.InvalidTypeCode:
|
||||
value := interface{}("")
|
||||
|
@ -546,7 +546,7 @@ func TestValidateCustomResource(t *testing.T) {
|
||||
},
|
||||
failingObjects: []failingObject{
|
||||
{object: map[string]interface{}{"fieldX": map[string]interface{}{"a": true, "b": true, "c": true}}, expectErrs: []string{
|
||||
`fieldX: Too many: must have at most 2 items`,
|
||||
`fieldX: Too many: 3: must have at most 2 items`,
|
||||
}},
|
||||
},
|
||||
},
|
||||
@ -561,7 +561,7 @@ func TestValidateCustomResource(t *testing.T) {
|
||||
},
|
||||
failingObjects: []failingObject{
|
||||
{object: map[string]interface{}{"fieldX": []interface{}{"a", "b", "c"}}, expectErrs: []string{
|
||||
`fieldX: Too many: 3: has too many items`,
|
||||
`fieldX: Too many: 3: must have at most 2 items`,
|
||||
}},
|
||||
},
|
||||
},
|
||||
@ -576,7 +576,7 @@ func TestValidateCustomResource(t *testing.T) {
|
||||
},
|
||||
failingObjects: []failingObject{
|
||||
{object: map[string]interface{}{"fieldX": "abc"}, expectErrs: []string{
|
||||
`fieldX: Too long: value is too long`,
|
||||
`fieldX: Too long: may not be longer than 2`,
|
||||
}},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user